kmp-koin-di
Use when wiring Koin dependency injection across a Kotlin Multiplatform app - commonMain vs androidMain/iosMain platform modules, initKoin or doInitKoin called from Swift, startKoin in Application, koinViewModel in Compose Multiplatform, the Koin Compiler Plugin or a [KOIN-D001]
Install
npx skills add https://github.com/Kushpawan/kmp-mobile-skills/tree/main/skills/kmp-koin-di
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install kushpawan-kmp-mobile-skills@llmmart
git clone https://github.com/Kushpawan/kmp-mobile-skills.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole kushpawan/kmp-mobile-skills collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Koin in Kotlin Multiplatform
Shared definitions live in commonMain, one platform module holds what only Android or iOS can
build, and one shared start function runs once per process on each platform. With the Koin Compiler
Plugin the build checks the graph; without it, a test does. This skill owns those KMP conventions;
Koin API detail belongs to the official Koin skills.
When to use
- Laying out Koin modules across
commonMain,androidMainandiosMain, or adding a feature, ViewModel or platform binding to a KMP graph. - Starting Koin from the Android
Applicationand from Swift; Koin-backed objects in SwiftUI code. NoDefinitionFoundException,KoinApplicationAlreadyStartedException,KoinApplication has not been started(often iOS only), or[KOIN-D001]only when the shared or app module compiles.- Koin tests in
commonTestthat leak state or need fakes for platform bindings. - No DI yet:
koin-setupfirst for Gradle and style, then this skill for the KMP layout.
When not to use
Use the official Koin skills (/plugin marketplace add InsertKoinIO/koin-skills, then
/plugin install koin@koin-skills; other agents: npx skills add InsertKoinIO/koin-skills):
| Need | Official skill |
|---|---|
| Definition syntax, qualifiers, scopes, Android-only entry points | koin |
| Koin in a project with no DI, Annotations vs DSL, Gradle versions | koin-setup |
| Hilt, Dagger, Kodein, Metro, Koin 3.x or Koin KSP to Koin 4 + Compiler Plugin | di-migration |
A [KOIN-…] code or org.koin.core.error.* trace not explained here; slow start-up, duplicates |
koin-diagnose |
Also not for a project on another DI framework it keeps (follow it), what the repositories and
clients are (kmp-data-layer), or expect/actual design beyond bindings (kmp-expect-actual).
Step 0 — Read the project first
grep -nE "koin|^kotlin *=|ksp" gradle/libs.versions.toml
grep -rnE "io.insert-koin.compiler.plugin|koin.compiler|koin-ksp-compiler|koinCompiler" --include=*.kts --include=*.toml .
grep -rnE "startKoin|initKoin|koinApplication|KoinApplication\(|@KoinApplication" --include=*.kt --include=*.swift .
grep -rnE "@Module|@Singleton|@KoinViewModel|single<|viewModel<|singleOf\(|single *\{" --include=*.kt . | head
grep -rnE "\.verify\(|checkModules|KoinContext" --include=*.kt . | head
| Finding | Then |
|---|---|
| Compiler Plugin applied | The build checks the graph. No verify() / checkModules() tests. Keep the project's DSL form or Annotations. |
| Koin 4 DSL, no plugin | Follow its form (singleOf(::X) or single { X(get()) }); the graph check is a JVM verify() test. Mention the plugin once — adding it is a Gradle change (di-migration), not a rewrite. |
Koin Annotations + KSP (koin-ksp-compiler), or Koin 3.x |
Match the existing artifacts and imports; add no KSP use. Moving off them is di-migration. |
| Annotations with the plugin | Annotated classes, @Module expect class PlatformModule — references/kmp-variants.md. Do not mix styles. |
Existing initKoin / initApp |
Extend it. Never add a second startKoin. |
KoinContext { } in Compose |
Deprecated and not needed — remove it when you touch the file. |
| Kotlin vs plugin version | Plugin 1.2.3 lists Kotlin 2.3.20–2.4.20; a newer Kotlin only warns. Check the plugin release notes before bumping either. |
As of 3 Dec 2026: Koin 4.2.2 (4.3.0-Beta1 is a pre-release), plugin 1.2.3. The official skills treat Kotlin 2.3.20, Koin 4.2.2 and plugin 1.2.3 as floors. Keep a project's existing pins.
Workflow
1. Dependencies
# gradle/libs.versions.toml
[versions]
koin = "4.2.2" # floor; a new setup takes the latest stable from Maven Central
koin-plugin = "1.2.3" # the plugin is not in the BOM
[libraries]
koin-bom = { module = "io.insert-koin:koin-bom", version.ref = "koin" }
koin-core = { module = "io.insert-koin:koin-core" }
koin-android = { module = "io.insert-koin:koin-android" }
koin-compose-viewmodel = { module = "io.insert-koin:koin-compose-viewmodel" }
koin-test = { module = "io.insert-koin:koin-test" }
[plugins]
koin-compiler = { id = "io.insert-koin.compiler.plugin", version.ref = "koin-plugin" }
// shared/build.gradle.kts — plus plugins { alias(libs.plugins.koin.compiler) }; no per-target setup
kotlin.sourceSets {
commonMain.dependencies {
implementation(project.dependencies.platform(libs.koin.bom))
implementation(libs.koin.core)
implementation(libs.koin.compose.viewmodel) // only with Compose UI; add koin-compose for koinInject()
}
androidMain.dependencies { implementation(libs.koin.android) }
commonTest.dependencies { implementation(libs.koin.test) }
}
Add koin-annotations for the Annotations style or @InjectedParam in DSL. Apply the plugin in
every module that declares definitions (multi-module).
2. Common modules, one platform module
// commonMain — profile/di/ProfileModule.kt (Compiler Plugin DSL: import org.koin.plugin.module.dsl.*)
val profileModule = module {
single<ProfileRepositoryImpl>() bind ProfileRepository::class
factory<GetProfileUseCase>()
viewModel<ProfileViewModel>()
}
// No plugin (Constructor DSL, org.koin.core.module.dsl.*): singleOf(::ProfileRepositoryImpl) bind …,
// factoryOf(::GetProfileUseCase), viewModelOf(::ProfileViewModel)
// commonMain — di/PlatformModule.kt
expect fun platformModule(): Module
// androidMain — di/PlatformModule.android.kt
actual fun platformModule(): Module = module {
single<AndroidSecureStore>() bind SecureStore::class // takes Context, set by androidContext()
}
// iosMain — di/PlatformModule.ios.kt
actual fun platformModule(): Module = module {
single<KeychainSecureStore>() bind SecureStore::class
}
Only the platform module names platform classes. Engines and drivers built by a call
(Darwin.create(), a SQL driver) go there as lambda definitions. Keep an existing expect val.
3. Start Koin once: platform init, then the logger, then Koin
// commonMain — di/Koin.kt
val appModule = module {
includes(coreModule, networkModule, profileModule, platformModule())
}
fun initKoin(config: KoinAppDeclaration? = null) {
startKoin { // the plugin checks the full graph where startKoin compiles
includes(config) // platform extras only: androidContext, logger
modules(appModule) // name it directly: modules(*list) or if/else is not checked (KOIN-W003)
}
}
// androidApp — ExampleApplication.onCreate(); AppLogging stands for the project's own init
AppLogging.init(isDebug = BuildConfig.DEBUG)
initKoin { androidContext(this@ExampleApplication); androidLogger() }
// iosMain — di/KoinIos.kt
fun initKoinIos() = initKoin() // no lambda for Swift to pass
// iosApp/iOSApp.swift
import Shared
@main
struct iOSApp: App {
init() { KoinIosKt.doInitKoinIos() } // file KoinIos.kt → KoinIosKt; "init…" gains a "do" prefix
var body: some Scene { WindowGroup { ContentView() } }
}
- The Swift name follows the Kotlin file name; SKIE or Swift export can change it — check the
generated header. Start Koin before the first
MainViewController()or Swift call into Koin. - Starting from the Compose root instead: references/kmp-variants.md. Never both.
4. ViewModels in commonMain
class ProfileViewModel(
@InjectedParam private val profileId: String, // passed with parametersOf; checked by the plugin
private val getProfile: GetProfileUseCase,
) : ViewModel()
@Composable
fun ProfileRoute(profileId: String, viewModel: ProfileViewModel = koinViewModel { parametersOf(profileId) }) {
val state by viewModel.state.collectAsStateWithLifecycle()
ProfileScreen(state = state, onRetry = viewModel::retry)
}
- Import
org.koin.compose.viewmodel.koinViewModel; in a navigation destination it lives as long as the back-stack entry.SavedStateHandleis injected without a declaration — arguments that must survive process death belong there, not inparametersOf. - No plugin: drop
@InjectedParam, declareviewModel { (profileId: String) -> ProfileViewModel(profileId, get()) }. activityViewModel()is Android-only. Scopes that work in KMP.
5. Koin-backed objects in Swift
Swift cannot call Koin's reified get<T>(). A narrow iosMain helper is the accepted place for
KoinComponent — class ProfileDependencies : KoinComponent { fun getProfileUseCase(): GetProfileUseCase = get() }
— while shared classes keep constructor injection. A shared ViewModel handed to SwiftUI needs an owner that clears it (kmp-swiftui-interop).
Swift classes that implement Kotlin interfaces: references/kmp-variants.md.
6. Tests in commonTest
Construct classes with fakes; when wiring matters, an isolated koinApplication { } with an
override module loaded last; stopKoin() after any test that used startKoin. Graph check: the
build with the plugin, a JVM verify() test without it. Detail: references/testing.md.
Quick reference
| Task | KMP convention |
|---|---|
| Shared start | initKoin(config) in commonMain: startKoin { includes(config); modules(appModule) } |
| Android / iOS start | initKoin { androidContext(this@App) } · KoinIosKt.doInitKoinIos() in App.init |
| Platform bindings | expect fun platformModule(): Module, included by appModule |
| ViewModel | viewModel<T>() (plugin) or viewModelOf(::T); koinViewModel() in Compose |
| Graph check | Build (plugin) · verify() JVM test (no plugin) |
| Test fake | koinApplication { modules(appModule, testOverrides) } |
Verify
Report each check as PASS, FAIL or NOT RUN (with the reason). Task names vary — list them with
./gradlew :shared:tasks --all | grep -i compile.
./gradlew :shared:compileKotlinIosSimulatorArm64 # plugin: the graph check runs here
./gradlew :shared:compileAndroidMain # or the project's Android compile task
./gradlew :shared:allTests # commonTest on every target (+ verify() if no plugin)
./gradlew :shared:linkDebugFrameworkIosSimulatorArm64 # Swift-facing helpers compile into the framework
grep -rn "startKoin" --include=*.kt . | grep -v Test # exactly one production call site
- Check that the check runs (plugin; the user's step): remove a needed definition, build,
expect
[KOIN-D001], restore. Green means the plugin does not see the modules. - Launch on Android and the iOS simulator; open one screen per feature you wired.
Common mistakes
| Mistake | Why it bites | Fix |
|---|---|---|
startKoin in the Application and in a shared helper |
KoinApplicationAlreadyStartedException |
One initKoin; platforms call it |
Swift calls shared code before doInitKoinIos() |
KoinApplication has not been started, iOS only |
Start in App.init / didFinishLaunching |
Logger or platform holder initialised after startKoin |
Early-built instances crash or log unredacted | Platform init, logger, then Koin |
verify() / checkModules() tests beside the plugin |
Duplicate the build check; checkModules() is deprecated |
Build plus "check that the check runs" |
modules(*list) or modules(if (debug) a else b) |
Graph check skipped (KOIN-W003) |
Pass the module directly |
| Plugin only on the app module | Feature definitions invisible to the check | Apply it to every module with definitions |
single<T>() where the plugin is not applied |
Compiles, then NotImplementedError |
Apply the plugin to that module |
MockK-based Koin tests in commonTest |
MockK does not run on iOS | Hand-written fakes in an override module |
| Tests share a started Koin | Order-dependent failures | koinApplication { }, or stopKoin() in @AfterTest |
Related skills
- kmp-data-layer — what the network and repository modules provide.
- kmp-room-database, kmp-secure-storage — platform bindings for the database and secure store.
- kmp-expect-actual (platform abstractions) and kmp-swiftui-interop (ViewModels in SwiftUI).
- kmp-testing-patterns — fakes, dispatchers and Turbine around these tests.
- Official Koin skills: https://github.com/InsertKoinIO/koin-skills (
koin,koin-setup,di-migration,koin-diagnose). Their plugin bundles an optional Kotzilla MCP server that sends error and session data to a third-party platform once signed in — enable it only if the user asks. - Koin docs: KMP setup, Compiler Plugin, compile-time safety.
Files (kmp-mobile-skills)
-
references
-
kmp-variants.md 4.7 KB
Loading… -
testing.md 6.4 KB
Loading…
-
-
SKILL.md 14.2 KB
--- name: kmp-koin-di description: Use when wiring Koin dependency injection across a Kotlin Multiplatform app - commonMain vs androidMain/iosMain platform modules, initKoin or doInitKoin called from Swift, startKoin in Application, koinViewModel in Compose Multiplatform, the Koin Compiler Plugin or a [KOIN-D001] error in a shared module, test overrides in commonTest - or on NoDefinitionFoundException, KoinApplicationAlreadyStartedException, "KoinApplication has not been started" or a launch crash only on iOS. For Koin-only API questions or migrating from Hilt/Dagger, the official koin and di-migration skills. license: Apache-2.0 compatibility: Kotlin Multiplatform project (Android + iOS) using or adopting Koin 4.x. The Koin Compiler Plugin path needs Kotlin 2.3.20+, Koin 4.2.2+ and plugin 1.2.3+. iOS steps need macOS with Xcode. metadata: category: data platforms: android, ios --- # Koin in Kotlin Multiplatform Shared definitions live in `commonMain`, one platform module holds what only Android or iOS can build, and one shared start function runs once per process on each platform. With the Koin Compiler Plugin the build checks the graph; without it, a test does. This skill owns those KMP conventions; Koin API detail belongs to the official [Koin skills](https://github.com/InsertKoinIO/koin-skills). ## When to use - Laying out Koin modules across `commonMain`, `androidMain` and `iosMain`, or adding a feature, ViewModel or platform binding to a KMP graph. - Starting Koin from the Android `Application` and from Swift; Koin-backed objects in SwiftUI code. - `NoDefinitionFoundException`, `KoinApplicationAlreadyStartedException`, `KoinApplication has not been started` (often iOS only), or `[KOIN-D001]` only when the shared or app module compiles. - Koin tests in `commonTest` that leak state or need fakes for platform bindings. - No DI yet: `koin-setup` first for Gradle and style, then this skill for the KMP layout. ## When not to use Use the official Koin skills (`/plugin marketplace add InsertKoinIO/koin-skills`, then `/plugin install koin@koin-skills`; other agents: `npx skills add InsertKoinIO/koin-skills`): | Need | Official skill | |---|---| | Definition syntax, qualifiers, scopes, Android-only entry points | [`koin`](https://github.com/InsertKoinIO/koin-skills/blob/main/skills/koin/SKILL.md) | | Koin in a project with no DI, Annotations vs DSL, Gradle versions | [`koin-setup`](https://github.com/InsertKoinIO/koin-skills/blob/main/skills/koin-setup/SKILL.md) | | Hilt, Dagger, Kodein, Metro, Koin 3.x or Koin KSP to Koin 4 + Compiler Plugin | [`di-migration`](https://github.com/InsertKoinIO/koin-skills/blob/main/skills/di-migration/SKILL.md) | | A `[KOIN-…]` code or `org.koin.core.error.*` trace not explained here; slow start-up, duplicates | [`koin-diagnose`](https://github.com/InsertKoinIO/koin-skills/blob/main/skills/koin-diagnose/SKILL.md) | Also not for a project on another DI framework it keeps (follow it), what the repositories and clients are (**kmp-data-layer**), or `expect`/`actual` design beyond bindings (**kmp-expect-actual**). ## Step 0 — Read the project first ```bash grep -nE "koin|^kotlin *=|ksp" gradle/libs.versions.toml grep -rnE "io.insert-koin.compiler.plugin|koin.compiler|koin-ksp-compiler|koinCompiler" --include=*.kts --include=*.toml . grep -rnE "startKoin|initKoin|koinApplication|KoinApplication\(|@KoinApplication" --include=*.kt --include=*.swift . grep -rnE "@Module|@Singleton|@KoinViewModel|single<|viewModel<|singleOf\(|single *\{" --include=*.kt . | head grep -rnE "\.verify\(|checkModules|KoinContext" --include=*.kt . | head ``` | Finding | Then | |---|---| | Compiler Plugin applied | The build checks the graph. No `verify()` / `checkModules()` tests. Keep the project's DSL form or Annotations. | | Koin 4 DSL, no plugin | Follow its form (`singleOf(::X)` or `single { X(get()) }`); the graph check is a JVM `verify()` test. Mention the plugin once — adding it is a Gradle change (`di-migration`), not a rewrite. | | Koin Annotations + KSP (`koin-ksp-compiler`), or Koin 3.x | Match the existing artifacts and imports; add no KSP use. Moving off them is `di-migration`. | | Annotations with the plugin | Annotated classes, `@Module expect class PlatformModule` — [references/kmp-variants.md](references/kmp-variants.md). Do not mix styles. | | Existing `initKoin` / `initApp` | Extend it. Never add a second `startKoin`. | | `KoinContext { }` in Compose | Deprecated and not needed — remove it when you touch the file. | | Kotlin vs plugin version | Plugin 1.2.3 lists Kotlin 2.3.20–2.4.20; a newer Kotlin only warns. Check the [plugin release notes](https://github.com/InsertKoinIO/koin-compiler-plugin/releases) before bumping either. | As of 3 Dec 2026: Koin 4.2.2 (4.3.0-Beta1 is a pre-release), plugin 1.2.3. The official skills treat Kotlin 2.3.20, Koin 4.2.2 and plugin 1.2.3 as floors. Keep a project's existing pins. ## Workflow ### 1. Dependencies ```toml # gradle/libs.versions.toml [versions] koin = "4.2.2" # floor; a new setup takes the latest stable from Maven Central koin-plugin = "1.2.3" # the plugin is not in the BOM [libraries] koin-bom = { module = "io.insert-koin:koin-bom", version.ref = "koin" } koin-core = { module = "io.insert-koin:koin-core" } koin-android = { module = "io.insert-koin:koin-android" } koin-compose-viewmodel = { module = "io.insert-koin:koin-compose-viewmodel" } koin-test = { module = "io.insert-koin:koin-test" } [plugins] koin-compiler = { id = "io.insert-koin.compiler.plugin", version.ref = "koin-plugin" } ``` ```kotlin // shared/build.gradle.kts — plus plugins { alias(libs.plugins.koin.compiler) }; no per-target setup kotlin.sourceSets { commonMain.dependencies { implementation(project.dependencies.platform(libs.koin.bom)) implementation(libs.koin.core) implementation(libs.koin.compose.viewmodel) // only with Compose UI; add koin-compose for koinInject() } androidMain.dependencies { implementation(libs.koin.android) } commonTest.dependencies { implementation(libs.koin.test) } } ``` Add `koin-annotations` for the Annotations style or `@InjectedParam` in DSL. Apply the plugin in every module that declares definitions ([multi-module](references/kmp-variants.md#3-multi-module-builds-and-the-plugin)). ### 2. Common modules, one platform module ```kotlin // commonMain — profile/di/ProfileModule.kt (Compiler Plugin DSL: import org.koin.plugin.module.dsl.*) val profileModule = module { single<ProfileRepositoryImpl>() bind ProfileRepository::class factory<GetProfileUseCase>() viewModel<ProfileViewModel>() } // No plugin (Constructor DSL, org.koin.core.module.dsl.*): singleOf(::ProfileRepositoryImpl) bind …, // factoryOf(::GetProfileUseCase), viewModelOf(::ProfileViewModel) // commonMain — di/PlatformModule.kt expect fun platformModule(): Module // androidMain — di/PlatformModule.android.kt actual fun platformModule(): Module = module { single<AndroidSecureStore>() bind SecureStore::class // takes Context, set by androidContext() } // iosMain — di/PlatformModule.ios.kt actual fun platformModule(): Module = module { single<KeychainSecureStore>() bind SecureStore::class } ``` Only the platform module names platform classes. Engines and drivers built by a call (`Darwin.create()`, a SQL driver) go there as lambda definitions. Keep an existing `expect val`. ### 3. Start Koin once: platform init, then the logger, then Koin ```kotlin // commonMain — di/Koin.kt val appModule = module { includes(coreModule, networkModule, profileModule, platformModule()) } fun initKoin(config: KoinAppDeclaration? = null) { startKoin { // the plugin checks the full graph where startKoin compiles includes(config) // platform extras only: androidContext, logger modules(appModule) // name it directly: modules(*list) or if/else is not checked (KOIN-W003) } } // androidApp — ExampleApplication.onCreate(); AppLogging stands for the project's own init AppLogging.init(isDebug = BuildConfig.DEBUG) initKoin { androidContext(this@ExampleApplication); androidLogger() } // iosMain — di/KoinIos.kt fun initKoinIos() = initKoin() // no lambda for Swift to pass ``` ```swift // iosApp/iOSApp.swift import Shared @main struct iOSApp: App { init() { KoinIosKt.doInitKoinIos() } // file KoinIos.kt → KoinIosKt; "init…" gains a "do" prefix var body: some Scene { WindowGroup { ContentView() } } } ``` - The Swift name follows the Kotlin file name; SKIE or Swift export can change it — check the generated header. Start Koin before the first `MainViewController()` or Swift call into Koin. - Starting from the Compose root instead: [references/kmp-variants.md](references/kmp-variants.md#2-starting-koin-from-compose). Never both. ### 4. ViewModels in commonMain ```kotlin class ProfileViewModel( @InjectedParam private val profileId: String, // passed with parametersOf; checked by the plugin private val getProfile: GetProfileUseCase, ) : ViewModel() @Composable fun ProfileRoute(profileId: String, viewModel: ProfileViewModel = koinViewModel { parametersOf(profileId) }) { val state by viewModel.state.collectAsStateWithLifecycle() ProfileScreen(state = state, onRetry = viewModel::retry) } ``` - Import `org.koin.compose.viewmodel.koinViewModel`; in a navigation destination it lives as long as the back-stack entry. `SavedStateHandle` is injected without a declaration — arguments that must survive process death belong there, not in `parametersOf`. - No plugin: drop `@InjectedParam`, declare `viewModel { (profileId: String) -> ProfileViewModel(profileId, get()) }`. - `activityViewModel()` is Android-only. [Scopes that work in KMP](references/kmp-variants.md#5-scopes-that-work-on-every-platform). ### 5. Koin-backed objects in Swift Swift cannot call Koin's reified `get<T>()`. A narrow `iosMain` helper is the accepted place for `KoinComponent` — `class ProfileDependencies : KoinComponent { fun getProfileUseCase(): GetProfileUseCase = get() }` — while shared classes keep constructor injection. A shared `ViewModel` handed to SwiftUI needs an owner that clears it (**kmp-swiftui-interop**). Swift classes that implement Kotlin interfaces: [references/kmp-variants.md](references/kmp-variants.md#4-swift-implemented-bindings). ### 6. Tests in commonTest Construct classes with fakes; when wiring matters, an isolated `koinApplication { }` with an override module loaded last; `stopKoin()` after any test that used `startKoin`. Graph check: the build with the plugin, a JVM `verify()` test without it. Detail: [references/testing.md](references/testing.md). ## Quick reference | Task | KMP convention | |---|---| | Shared start | `initKoin(config)` in `commonMain`: `startKoin { includes(config); modules(appModule) }` | | Android / iOS start | `initKoin { androidContext(this@App) }` · `KoinIosKt.doInitKoinIos()` in `App.init` | | Platform bindings | `expect fun platformModule(): Module`, included by `appModule` | | ViewModel | `viewModel<T>()` (plugin) or `viewModelOf(::T)`; `koinViewModel()` in Compose | | Graph check | Build (plugin) · `verify()` JVM test (no plugin) | | Test fake | `koinApplication { modules(appModule, testOverrides) }` | ## Verify Report each check as `PASS`, `FAIL` or `NOT RUN` (with the reason). Task names vary — list them with `./gradlew :shared:tasks --all | grep -i compile`. ```bash ./gradlew :shared:compileKotlinIosSimulatorArm64 # plugin: the graph check runs here ./gradlew :shared:compileAndroidMain # or the project's Android compile task ./gradlew :shared:allTests # commonTest on every target (+ verify() if no plugin) ./gradlew :shared:linkDebugFrameworkIosSimulatorArm64 # Swift-facing helpers compile into the framework grep -rn "startKoin" --include=*.kt . | grep -v Test # exactly one production call site ``` - **Check that the check runs** (plugin; the user's step): remove a needed definition, build, expect `[KOIN-D001]`, restore. Green means the plugin does not see the modules. - Launch on Android and the iOS simulator; open one screen per feature you wired. ## Common mistakes | Mistake | Why it bites | Fix | |---|---|---| | `startKoin` in the `Application` and in a shared helper | `KoinApplicationAlreadyStartedException` | One `initKoin`; platforms call it | | Swift calls shared code before `doInitKoinIos()` | `KoinApplication has not been started`, iOS only | Start in `App.init` / `didFinishLaunching` | | Logger or platform holder initialised after `startKoin` | Early-built instances crash or log unredacted | Platform init, logger, then Koin | | `verify()` / `checkModules()` tests beside the plugin | Duplicate the build check; `checkModules()` is deprecated | Build plus "check that the check runs" | | `modules(*list)` or `modules(if (debug) a else b)` | Graph check skipped (`KOIN-W003`) | Pass the module directly | | Plugin only on the app module | Feature definitions invisible to the check | Apply it to every module with definitions | | `single<T>()` where the plugin is not applied | Compiles, then `NotImplementedError` | Apply the plugin to that module | | MockK-based Koin tests in `commonTest` | MockK does not run on iOS | Hand-written fakes in an override module | | Tests share a started Koin | Order-dependent failures | `koinApplication { }`, or `stopKoin()` in `@AfterTest` | ## Related skills - **kmp-data-layer** — what the network and repository modules provide. - **kmp-room-database**, **kmp-secure-storage** — platform bindings for the database and secure store. - **kmp-expect-actual** (platform abstractions) and **kmp-swiftui-interop** (ViewModels in SwiftUI). - **kmp-testing-patterns** — fakes, dispatchers and Turbine around these tests. - Official Koin skills: <https://github.com/InsertKoinIO/koin-skills> (`koin`, `koin-setup`, `di-migration`, `koin-diagnose`). Their plugin bundles an optional Kotzilla MCP server that sends error and session data to a third-party platform once signed in — enable it only if the user asks. - Koin docs: [KMP setup](https://insert-koin.io/docs/reference/koin-core/kmp-setup), [Compiler Plugin](https://insert-koin.io/docs/setup/compiler-plugin), [compile-time safety](https://insert-koin.io/docs/reference/koin-compiler/compile-safety).
Reviews (0)
No reviews yet.
Comments
Sign in to join the conversation.
No comments yet. Start the conversation.