I just started using Koin lib in an android (to replace Dagger 2) project which was prepared for tests. I have an issue with the android app context in module:
val M = module {
val ctx = androidApplication() //here error
}
Koin is started in App class:
import android.app.Application
import android.content.Context
import org.koin.android.ext.android.startKoin
class App : Application() {
override fun onCreate() {
super.onCreate()
startKoin(this, listOf(M))
}
}
I get log:
D/App: onCreate()
I/KOIN: [context] create
E/KOIN: [ERROR] - Error while resolving instance for class 'android.app.Application' - error: org.koin.error.NoBeanDefFoundException: No compatible definition found for type 'Application'. Check your module definition
and the app crashes. Did I miss something in the configuration of Koin? In the target project, I have a few modules which deeply depend on application context. And I don't want to use a global reference to this context.
Solution is easy but not so obvious.
Somehow Android Studio imports standalone startKoin function instead of specific android function.
So you had to replace
import org.koin.standalone.StandAloneContext.startKoin
To
import org.koin.android.ext.android.startKoin
in Application
class
Do tell if this works or not.