Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R8 Crashes Silently on Build

I get the following warning - error when building an Android release.

WARNING:R8: Unexpected error during rewriting of Kotlin metadata for class 'androidx.lifecycle.LifecycleController$observer$1':
com.android.tools.r8.internal.sG: lateinit property function has not been initialized
    at com.android.tools.r8.internal.Xn.a(SourceFile:302)
    at com.android.tools.r8.internal.Kn.a(SourceFile:49)
    at com.android.tools.r8.internal.Kn.a(SourceFile:24)
    at com.android.tools.r8.utils.V.a(SourceFile:36)
    at com.android.tools.r8.utils.V.a(SourceFile:41)
    at com.android.tools.r8.utils.V.a(SourceFile:35)
    at java.base/java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1448)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

Usually I wouldn't have given much attention to a warning.

But we're experiencing a related lifecycle bug in release (like the observer doesn't work at all).

I've tried -keepclasseswithmembers class androidx.lifecycle.LifecycleController.** { *; } with no luck.

like image 313
rtsketo Avatar asked Nov 15 '22 19:11

rtsketo


1 Answers

Applying the R8 plugin in my Project lvl gradle fix this issue for me:

buildscript {

    repositories {
        maven {
            url 'https://storage.googleapis.com/r8-releases/raw'
        }
    }

    dependencies {
        classpath 'com.android.tools:r8:3.0.65'          // Must be before the Gradle Plugin for Android.
        classpath 'com.android.tools.build:gradle:X.Y.Z' // Your current AGP version.
     }
}
like image 117
Kevin ABRIOUX Avatar answered Dec 16 '22 01:12

Kevin ABRIOUX