Koin Android: org.koin.error.NoBeanDefFoundException
Solution is easy but not so obvious.
Somehow Android Studio imported standalone startKoin
function instead of specific android function.
So I had to replace
import org.koin.standalone.StandAloneContext.startKoin
To
import org.koin.android.ext.android.startKoin
And that works!
I had similar issue , Try to just add this dependency it will be resolved
// Room
implementation "android.arch.persistence.room:runtime:1.1.1"
kapt "android.arch.persistence.room:compiler:1.1.1" .
In my case I needed to make like this:
import android.app.Application
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidFileProperties
import org.koin.android.ext.koin.androidLogger
import org.koin.android.viewmodel.dsl.viewModel
import org.koin.core.context.startKoin
import org.koin.core.module.Module
import org.koin.dsl.module
class MyApplication : Application() {
override fun onCreate(){
super.onCreate()
// start Koin!
startKoin {
// Android context
androidLogger()
androidContext(this@MyApplication)
// use the Android context given there
// load properties from assets/koin.properties file
androidFileProperties()
// modules
modules(myModule)
}
}
val myModule: Module = module { viewModel { MyViewModel() }}
}
and use older dependencies:
implementation("org.koin:koin-android:2.0.1")
implementation("org.koin:koin-android-viewmodel:2.0.1")