IllegalStateException: at org.koin.core.context.GlobalContext.get
See original GitHub issueI’ve just released an app using Koin 2.2.2
and I’m seeing crash reports on devices running Android 8.1 (SDK 27). I haven’t seen it on any other versions of Android yet, so it could be a bug in 8.1. So far, the devices it’s crashing on are Motorola Moto G Plus
and something called DigiLand DL1016
. Edit: Actually, I just got a crash report on Samsung Galaxy Note8
running Android 9 (SDK 28). So it’s not just 8.1.
I’m just calling getViewModel<MyViewModel>()
in MainActivity.onCreate().
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2861)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2943)
at android.app.ActivityThread.-wrap11 (Unknown Source)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1630)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6626)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:811)
Caused by: java.lang.IllegalStateException:
at org.koin.core.context.GlobalContext.get (GlobalContext.java:1)
at org.koin.android.ext.android.ComponentCallbackExtKt.getKoin (ComponentCallbackExtKt.java:1)
at org.koin.androidx.viewmodel.ext.android.ActivityExtKt.getViewModel (ActivityExtKt.java:1)
at com.mypackage.MainActivity.onCreate (MainActivity.java:1)
at android.app.Activity.performCreate (Activity.java:7032)
at android.app.Activity.performCreate (Activity.java:7023)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1236)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2814)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2943)
at android.app.ActivityThread.-wrap11 (Unknown Source)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1630)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6626)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:811)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:11
Top Results From Across the Web
java.lang.IllegalStateException: KoinApplication has not been ...
While running the application in catlog I see the following message. java.lang.IllegalStateException: KoinApplication has not been started.
Read more >Start Koin
The GlobalContext is a default JVM context strategy for Koin. It's called by startKoin and register to GlobalContext . This will allow us...
Read more >jvmMain.org.koin.core.context.GlobalContext.kt Maven ...
jvmMain.org.koin.core.context.GlobalContext.kt maven / gradle build tool code. The class is part of the package ➦ Group: io.insert-koin ➦ Artifact: ...
Read more >java.lang.ClassCastException: org.koin.core.context ...
I trying to migrate from Koin 2.1.6 to 2.2.2 or 3.0.1 but on both versions during run tests I have many issues related...
Read more >Dependency Injection with Kotlin and Koin - Auth0
Koin is a dependency injection framework for Kotlin. ... package com.matthewcasperson import org.koin.core.context.GlobalContext.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi everyone,
since I also got the error and it seems to be related to a similar issue I had with Dagger before migrating to Koin. It had to do with the app’s custom Application class not being used on some Android versions.
See following issues which seem to be related: https://github.com/InsertKoinIO/koin/issues/286#issuecomment-437994119 https://github.com/google/dagger/issues/748#issuecomment-339235062
I updated my apps as follows:
Instead of starting Koin in my Application class I am now starting it in my activities as follows:
I am still in staged rollout, but so far it looks promising. But with Dagger it took me several iterations because I could never reproduce this issue.
I do not know, I started using Koin with 2.2.2 and so cannot tell if any previous version has the same issue. My assumption is, any previous version depending on a custom Application class will face sooner or later some weired exceptions on 7.x and 8.x Android versions, sometimes this may even be vendor specific (saw it for some Samsung Android versions).
Actually I never received any user complaint about this, just a ton of crash reports on Google Play, never on Firebase. Seems to crash the app even before Crashlytics is ready. So at the end this could also just be some background app starting / house keeping of Android (read something about backup processes) that the user never notice. As said before I could never reproduce the issue, but with my code above the crash reports are gone.