InsertKoinIO / koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform
https://insert-koin.io
Apache License 2.0
9.1k stars 720 forks source link

koin-startup : GlobalContext.get java.lang.IllegalStateException - KoinApplication has not been started #2018

Closed florent37 closed 1 week ago

florent37 commented 1 month ago

Describe the bug

StackTrace :

After adding the koin-startup on my application, I face some crashs on startup after releasing the application on the play store

Fatal Exception: java.lang.RuntimeException: Unable to create application com.pairip.application.Application: java.lang.IllegalStateException: KoinApplication has not been started
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7234)
       at android.app.ActivityThread.-$$Nest$mhandleBindApplication()
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2284)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:240)
       at android.os.Looper.loop(Looper.java:351)
       at android.app.ActivityThread.main(ActivityThread.java:8377)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)

com.pairip.application.Application is not my package name, I suppose it's created by Playstore integrity if someone can confirm

Caused by java.lang.IllegalStateException: KoinApplication has not been started
       at org.koin.core.context.GlobalContext.get(GlobalContext.java:36)
       at org.koin.android.ext.android.AndroidKoinScopeExtKt.getKoinScope(AndroidKoinScopeExt.kt:33)
       at com.app.MyApplication.safedk_MyApplication_onCreate_fec88b9885feba93d26e7d52ea1c81b4(MyApplication.kt:21)
       at com.app.MyApplication.onCreate(MyApplication.kt:40)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1285)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7227)
       at android.app.ActivityThread.-$$Nest$mhandleBindApplication()
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2284)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:240)
       at android.os.Looper.loop(Looper.java:351)
       at android.app.ActivityThread.main(ActivityThread.java:8377)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)

To Reproduce Steps to reproduce the behavior:

  1. Bump koin to 4.0.0
  2. Install the module koin-startup
  3. add the method onKoinStartup on the init {
  4. Deploy the application on the playstore (it happens only after google adds the app-integrity mechanism
  5. Users launch the app, then it crashes on some devices

Koin module and version: koin:4.0.0 koin-startup:4.0.0

Snippet or Sample project to help reproduce

class MyApplication : Application() {

    init {
        onKoinStartup {
            initializeMyDependencies(
                application = this@MyApplication,
            )
        }
    }

    override fun onCreate() {
        super.onCreate()

        get<AnyUseCase>().invoke()
    }
}
santimattius commented 3 weeks ago

Investigating the error, it sounds to me like it is something that introduces play integrity in the artifact that ends up being distributed in the app. I did not find much information about it. But I leave some points for you to validate in your project:

I leave this link with interesting information about the packageName that appears in your stack traces https://github.com/Solaree/pairipcore

arnaudgiuliani commented 1 week ago

Let's reopen if needed