Yannick
Yannick

Reputation: 5912

Crash when using both Library Desugaring and R8/Proguard/minifyEnabled

I have a multi-module app (minSdk 21 , AGP 7.0.0-alpha12) that crashes on startup in release variant (Proguard/R8 enabled) when using Java 8 desugaring following this guide

I know this error is related to desugaring because if I enable desugaring the error occurs

compileOptions {
      coreLibraryDesugaringEnabled true
}

Whereas If I disable desugaring the error doesn't occur

compileOptions {
      coreLibraryDesugaringEnabled false
}

Stacktrace:

   java.lang.IncompatibleClassChangeError: Class j$.util.Collection implements non-interface class d.e (declaration of 'j$.util.Collection' appears in base.apk!classes2.dex)
        at ja.s.f(Unknown Source:0)
        at h4.g0.<clinit>(:4)
        at y5.d1.C(:1)
        at v8.f.<init>(:2)
        at com.luminarlab.fontboard.KeyboardApp.<init>(:2)
        at java.lang.Class.newInstance(Native Method)
        at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
        at androidx.core.app.CoreComponentFactory.instantiateApplication(Unknown Source:0)
        at android.app.Instrumentation.newApplication(Instrumentation.java:1155)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1223)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6431)
        at android.app.ActivityThread.access$1300(ActivityThread.java:219)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:940)

I tried fixing the error using -keep class java.util.** { *; } in proguard-rules.pro but it doesn't change anything.

Any help, hints or answers are appreciated. Thanks in advance!

Upvotes: 1

Views: 1403

Answers (1)

Yannick
Yannick

Reputation: 5912

As it turns out the guide on developers.android.com is outdated. As of now it uses coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.9' but the latest version is coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'. Updating to the latest version resolved my issue. You can find the latest version here

Upvotes: 3

Related Questions