There are two modules in my android project, app module and lib module.
Both these two modules need Koin for D.I., so I call startKoin
in MyApplication
class in app module, and IninKointContentProvider
in lib module as below.
// app module
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
startKoin(this, modules1)
}
}
// lib module
class InitKoinContentProvider : ContentProvider() {
override fun onCreate(): Boolean {
startKoin(context.applicationContext, modules2)
return true
}
}
Then app crashed and shown this message
Caused by: org.koin.error.BeanOverrideException: Try to override definition with Single [class='android.content.Context'], but override is not allowed. Use 'override' option in your definition or module.
I guess startKoin
can be called only one time.
The solution I found is merging two koin modules then calling startKoin
in MyApplication
, but I don't like it. Lib module may be imported by other android project which doesn't use koin, in that case, I think calling startKoin
in InitKoinContentProvider
is better.
Any solution for this problem?? Thanks!