A little late , But if somone else face similar issue.
Make sure Koin is initialized correctly in Application class: also add Logger to see the cause of error
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
startKoin {
androidLogger(Level.ERROR) // Or Level.DEBUG
androidContext(this@MyApp) // Important
modules(appModule)
}
}
}
Use androidApplication() inside a Koin module {}:
val appModule = module {
single {
Room.databaseBuilder(
androidApplication(), // safe only if Koin is started properly,
AppDatabase::class.java,
"wizards"
).build()
}
}
Check manifest: Ensure your Application class is set correctly:
<application
android:name=".MyApp"
...
if the error still persist , try with get()
val appModule = module {
single {
Room.databaseBuilder(
get(), // gets Context from Koin's DI container
AppDatabase::class.java,
"wizards"
).build()
}
}
Function | Description | Safety |
---|---|---|
androidApplication() |
Koin's shortcut to get Application context |
✅ Safe only after androidContext() is set up |
get() |
Fetches whatever is registered in Koin DI | ✅ Safe, as long as Context is provided via androidContext() |