简体   繁体   中英

Android app crashes when proguard enabled with release apk: NoClassDefFoundError: Failed resolution of: Lorg/koin/core/context/GlobalContextKt;

I am facing with problem (app crashes at start) with release apk, when enabling proguard.

Here is stack trace:

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.xxxx.yyyy, PID: 24018 java.lang.NoClassDefFoundError: Failed resolution of: Lorg/koin/core/context/GlobalContextKt; at com.xxxx.yyyy.MyApp.onCreate(MyApp.kt:31) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1202) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7349) at android.app.ActivityThread.access$2400(ActivityThread.java:308) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2295) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:219) at android.app.ActivityThread.main(ActivityThread.java:8347) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055) Caused by: java.lang.ClassNotFoundException: org.koin.core.context.GlobalContextKt at 8816 8970007088.xxxx.yyyy.MyApp.onCreate(MyApp.kt:31) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1202) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7349) at android.app.ActivityThread.access$2400(ActivityThread.java:308) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2295) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:219) at android.app.ActivityThread.main(ActivityThread.java:8347) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)

Here is my Application class, where I start koin:

```    class MyApp : Application() {
    companion object {
        var language: String? = null
    }

    @ExperimentalContracts
    override fun onCreate() {
        super.onCreate()

        // Start Koin
        startKoin {
            androidContext(this@MyApp)
            androidLogger(Level.DEBUG)
            modules(
                listOf(
                    appModule,
                    networkModule,
                    activityModules
                )
            )
        }
    }

    override fun attachBaseContext(base: Context?) {
        if (base != null) {
            super.attachBaseContext(LocaleHelper.onAttach(base))
        }
        else {
            super.attachBaseContext(base)
        }
    }
} ```

Koin version: 2.0.1 What is interesting that only crashes in release signed apk when minifyEnabled = true. But if debug build with minifyEnabled = true, it does not crashes. I am aware I didn't post more sample code but it is very difficult to investigate what causes crash from logs for release apk, Already read some issue reports on GitHub. but no help for me. Thanks for any advice!

I have found a problem. I totally forgot that last week I changed in gradle import for firebase-crashlytics library(using new way). Also removed keep class crashlytics in proguard-roles file.

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