0Pricing
Kotlin Multiplatform Academy · Lesson

Start Koin on Android & iOS

Initialize the graph from each platform's entry point.

Start Koin on Android & iOS is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Multiplatform Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

A Module Needs Starting

Declaring modules is only half the job. Each platform must start Koin at launch so the container is ready before anything asks for a dependency.

A Shared Init Helper

Put the common startup in shared code with a small initKoin function. Both platforms call it, so the wiring never drifts apart.

fun initKoin() = startKoin {
    modules(appModule())
}

Pass Extra Platform Config

Give initKoin a parameter so each platform can append its own setup, like Android needing the application context.

fun initKoin(extra: KoinAppDeclaration = {}) =
    startKoin { extra(); modules(appModule()) }

Start Koin on Android

On Android, call initKoin from your Application class so the graph exists for the whole process lifetime.

class App : Application() {
    override fun onCreate() {
        super.onCreate()
        initKoin()
    }
}

Give Android the Context

Android modules often need a Context. Pass it through the extra block using androidContext so definitions can resolve it.

initKoin { androidContext(this@App) }

Register the Application Class

Remember to point your manifest at the custom Application class, or onCreate never runs and Koin never starts.

Start Koin on iOS

On iOS you call the same initKoin through the generated framework, typically from your SwiftUI App init or AppDelegate.

Call It from Swift

Koin exposes a tiny helper so Swift can launch the graph in one clean line at app startup. 🍎

// Swift
KoinKt.doInitKoin()

Start Only Once

Call startKoin a single time per app launch. Starting it twice throws an error, so keep init in one obvious entry point.

Add Logging While Learning

Turn on printLogger during development so Koin prints what it builds, making missing-definition mistakes easy to spot.

startKoin {
    printLogger()
    modules(appModule())
}

One Graph, Two Entry Points

The key idea: the same modules load from two platform entry points. Android uses its Application, iOS uses its App init, both share the wiring.

Quick Check

Where should startup logic live?

Recap

You exposed a shared initKoin, called it from Android's Application and iOS's App init, and learned to start it once with optional logging. The graph is live on both. ✅

Frequently asked questions

Is the “Start Koin on Android & iOS” lesson free?

Yes — the full text of “Start Koin on Android & iOS” is free to read here on the web, and the Kotlin Multiplatform Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Multiplatform Academy course, upgrade to CoddyKit PRO.

What will I learn in “Start Koin on Android & iOS”?

Initialize the graph from each platform's entry point. You practise Kotlin Multiplatform Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Kotlin Multiplatform Academy?

No prior experience is required. Kotlin Multiplatform Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Start Koin on Android & iOS” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Kotlin Multiplatform Academy lesson?

Yes. Every Kotlin Multiplatform Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Declare a Shared Koin Module
  2. single vs factory Scopes
  3. Start Koin on Android & iOS
  4. Inject into ViewModels & Repos
← Back to Kotlin Multiplatform Academy