简体   繁体   中英

Get “org.koin.error.BeanOverrideException” error on reopen the app

I'm using Koin on a modular application by following documentation of that. I call startKoin on my BaseApplication on the Core-Module:

Application

val myModule = module {
    factory { MyClass(androidContext()) }
}

override fun onCreate() {
    super.onCreate()
    startKoin(this, listOf(myModule))
}

And load some other modules in other modules by loadKoinModules :

loadKoinModules(otherModules)

All things are ok on first run, but when I reopen the application, I'm getting this error:

com.example.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.app, PID: 8252
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.MainActivity}: org.koin.error.BeanOverrideException: Try to override definition with Factory [name='MyClass',class='com.example.module.MyClass'], but override is not allowed. Use 'override' option in your definition or module.
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Is there any way to destroy Koin or any other way to solving this problem?

Try this:

val myModule = module(override = true) {
    factory { MyClass(androidContext()) }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM