Create PicaApplication.kt — startKoin
The modules are declared — now they need to be started. That happens in an Application class, created once, before the first screen. In the code column — PicaApplication.kt with startKoin { }.
Two steps to make it work:
1. Register the class in AndroidManifest.xml (otherwise onCreate never runs):
<application
android:name=".PicaApplication"
... >
2. Add the Koin dependencies in build.gradle.kts (stack-when-needed):
implementation(platform(libs.koin.bom))
implementation(libs.koin.android)
implementation(libs.koin.androidx.compose) // koinViewModel()
And now — the last trace of manual wiring disappears. MenuScreen no longer builds the chain; it asks Koin for the ViewModel:
// BEFORE (lesson 5):
val vm: MenuViewModel = viewModel { MenuViewModel(MenuRepository(Network.api)) }
// NOW (Koin):
import org.koin.androidx.compose.koinViewModel
val vm: MenuViewModel = koinViewModel()
And delete object Network — it's gone, replaced by coreModule.
Verify. Run the app with the backend up. The menu loads exactly as in lesson 5 — the user sees no difference. But Logcat now shows Koin initializing, and object Network is gone from the code:
Logcat: [Koin] started with X definitions
On screen: the same pizza list from GET /menu
Gotcha. Forgot
android:name=".PicaApplication"in the manifest?startKoinnever runs, and the firstkoinViewModel()crashes immediately:org.koin.core.error.KoinApplicationNotStartedException: KoinApplication has not been startedThe symptom is misleading — it looks like a Koin config problem, when really your
Applicationclass never ran at all. Always check the manifest first.