R8 Crashes Silently on Build - android

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.

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.
}
}

Related

com.android.tools.r8.CompilationFailedException:Compilation failed to complete, position:Lcom/facebook/login/DefaultAudience$EnumUnboxingLocalUtility;

I have some error, after updated kotlin version (ext.kotlin_version) to 1.6.10:
com.android.tools.r8.internal.E00: Unexpected type in conversion to primitive: OBJECT
Execution failed for task ':app:minifyReleaseWithR8'.
> com.android.tools.r8.CompilationFailedException: Compilation failed to complete, position: Lcom/facebook/login/DefaultAudience$EnumUnboxingLocalUtility;getNativeProtocolAudience(I)Ljava/lang/String;, origin: ..\.gradle\caches\transforms-3\57102c4e3d32396b86898e5ca0dd620d\transformed\jetified-facebook-core-7.1.0-runtime.jar:com/facebook/login/DefaultAudience.class
It happened, if I use options minifyEnabled true in my build.gradle(:app) with Generate signed bundle.
If I use old ext.kotlin_version (for examle, 1.5.0) this error did not appear.
I think, if I use correct rule(s) in proguard-rules.pro I could resolve this issue.
This was caused by an issue in R8. Fix is available in R8 3.1.71, 3.2.55 and 3.3.26-dev versions.
Add the following to settings.gradle or settings.gradle.kts to use a specific version of R8 different from the one bundeled with AGP:
pluginManagement {
buildscript {
repositories {
mavenCentral()
maven {
url = uri("https://storage.googleapis.com/r8-releases/raw")
}
}
dependencies {
classpath("com.android.tools:r8:X.Y.Z")
classpath('com.google.guava:guava:30.1.1-jre') // <-- THIS IS REQUIRED UNTIL R8 3.2.4-dev
}
}
}
I find right rule for decide this problem.
You need add this code into proguard-rules.pro:
-keep class com.facebook.login.** {*;}
This line let ignore option minifyEnabled true for all files into com.facebook.login package.

VerifyError: Verifier rejected class ... 'this' arg must be initialized

after third-party library upgrade I got a new crash on app launch:
java.lang.VerifyError: Verifier rejected class ly.img.android.e: void ly.img.android.e.<init>(java.lang.String, boolean) failed to verify: void ly.img.android.e.<init>(java.lang.String, boolean): [0x5C] 'this' arg must be initialized (declaration of 'ly.img.android.e' appears in base.apk!classes2.dex)
at ly.img.android.b.<clinit>(Unknown Source:46)
at ly.img.android.c.b(Unknown Source:0)
at ly.img.android.PESDK.initSDK(Unknown Source:0)
at ly.img.android.IMGLYAutoInit.onCreate(IMGLYAutoInit.java:41)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2092)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2066)
at android.app.ActivityThread.installProvider(ActivityThread.java:6983)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6528)
Yes, I know that there are a lot of similar problems there but I didn't find any solution or advise for me.
So, maybe someone there can provide hint or advise for me what's wrong there. Thanks
Others were also facing this kind of issue, I think this can help you! ⛅
java.lang.VerifyError: Verifier rejected class ly.img.android.e: void ly.img.android.e.<init>(java.lang.String, boolean) failed to verify: void ly.img.android.e.<init>(java.lang.String, boolean): [0x5C] 'this' arg must be initialized (declaration of 'ly.img.android.e' appears in base.apk!classes2.dex)
But according to a GitHub thread they found a solution to this problem
https://github.com/CleverTap/clevertap-android-sdk/issues/15#issuecomment-454842450
The fix for this issue is available for AGP(Android Gradle Plugin) 3.3 (and 3.4) by setting an explicit dependency detailed below.
After AGP 3.3.1 is released, remove the pinned version to allow you to pick up new D8/R8 releases again.
For AGP 3.3 amend your top-level build.gradle file with:
buildscript {
repositories {
maven {
url "http://storage.googleapis.com/r8-releases/raw" // ADD THIS.
}
}
dependencies {
classpath 'com.android.tools:r8:1.3.52' // ADD THIS. Must be before the Gradle Plugin for Android.
classpath 'com.android.tools.build:gradle:3.3'
}
}
For AGP 3.4 the r8 version should be 1.4.25
I have a suggestion
Maybe it will help
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
and
implementation 'com.android.support:multidex:1.0.0'
How did I resolve the issue:
I have upgraded gradle version from 3.5.3 to 3.6.3. Ough and thank you. Maybe my experience can help somebody.
I think this is the probelm with third-party library.
In my case, I built the library .jar myself and had no idea why the VerifyError would appear when trying to test the .jar in a test application.
The problem was in proguard.cfg with -assumenosideeffects and Log.
Specifically, inside proguard.cfg (of my library) there was a following line:
-assumenosideeffects class android.util.Log {*;}
Replacing it with:
-assumenosideeffects class android.util.Log {
public static *** v(...);
public static *** d(...);
public static *** i(...);
public static *** w(...);
public static *** e(...);
}
and building and obfuscating it again resolved the problem.
I found the answer to my problem here.
I know this doesn't directly answer to the original question, but I left this answer here in order to help someone who is trying to build the .jar and the result of using it is VerifyError.
I had a similar error:
FATAL EXCEPTION: Connection#7864356
Process: ..., PID: 24458
java.lang.VerifyError: Verifier rejected class r8.a: r8.b r8.a.b(w8.a[]) failed to verify: r8.b r8.a.b(w8.a[]): [0x33] expected to be within a catch-all for an instruction where a monitor is held (declaration of 'r8.a' appears in /data/app/~~DIy9qxh1lGM...==/base.apk)
at p7.g$b.b(SourceFile:270)
at p7.g$b.run(SourceFile:35)
This happened after I updated gradle from 4.2.2 to 7.3.1. I tried disabling obfuscation and the #Keep option for the specified classes in the error message. But nothing helped. In debug mode, everything still worked, but in the release the app crashed with an error.
Thanks Dupinder Singh.
I've changed my top-level build.gradle file with:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools:r8:4.0.48'
classpath 'com.android.tools.build:gradle:7.3.1'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Now everything works. Maybe my solution will help someone.

Is R8 not support applyMapping?

Use applyMapping will lead to a compile exception, like:
R8: 'boolean readField(int)' already has a mapping
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithR8ForRelease'.
com.android.tools.r8.CompilationFailedException: Compilation failed to complete
My Android Gradle Plugin's version is 3.5.3, I find it's a question of R8. Because when disable R8, applyMapping work fine, enable the R8, it will not work.
I fond that the Mapping.txt generated by R8 has the duplicate methods like this:
1:1:boolean readField(int):0 -> a
2:2:boolean readField(int):0:0 -> a
If remove one of them, it will work fine.
You are using an older version of R8 that too eagerly reports error in the mapping file. Try to use an older version by adding the following to your top-level build.gradle file:
buildscript {
repositories {
maven {
url 'http://storage.googleapis.com/r8-releases/raw'
}
}
dependencies {
classpath 'com.android.tools:r8:1.6.60' // Must be before the Gradle Plugin for Android.
classpath 'com.android.tools.build:gradle:X.Y.Z' // Your current AGP version.
}
}
This should help out with your issue.

Force Gradle build to fail when releasing with SNAPSHOT dependencies

I would like to prevent the usage of SNAPSHOT dependencies when building with Gradle a release version of an Android application or library.
How can I force the Gradle build to fail if there are any SNAPSHOT dependencies when building the release?
You could use a ResolutionStrategy.
See here for the API:
https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
The below example was posted in the Gradle forums by Peter_Niederwieser
https://discuss.gradle.org/t/enforce-no-snapshot-dependencies-in-gradle/3851/2
configurations.all {
if (isRelease) {
resolutionStrategy.eachDependency { details ->
if (details.requested.version.endsWith("-SNAPSHOT")) {
throw new GradleException("found snapshot dependency")
}
}
}
}
The code must be placed either in the module build.gradle or in the "allprojects" section of the main build.gradle.

Using android Parceler library with minifyEnabled

Whenever I try to minify my project that makes use of the parceler library, I cannot build a release apk because of a lot of warnings from proguard. For example:
Warning:org.parceler.transfuse.gen.FilerResourceWriter: can't find referenced class javax.tools.FileObject
I don't even make use of most of the libraries reported in this messages. What I'd like to know is if someone has encountered this problem and managed to solve it.
I tried to use -dontwarn to suppress all messages, but it does not seems correct, and besides it makes my app crash in rare cases (which makes me thing that some of the warning messages are indeed correct, but I'd like the library to keep the needed classes automatically).
My gradle script is as follows:
apply plugin: 'com.android.application'
...
dependencies {
...
compile 'org.parceler:parceler:1.0.3'
}
You are seeing this error from Proguard because you've included Parceler as a runtime dependency. Parceler was designed to be included into your project as two separate libraries; the annotation processor and the api. If you're running Gradle your build script should look like the following:
compile "org.parceler:parceler-api:1.0.3"
apt "org.parceler:parceler:1.0.3"
See Getting Parceler.
where apt is the android-apt plugin. Secondarily, it can also be run under the provided scope.
Your build script will look like the following in the end:
buildscript {
repositories {
mavenCentral()
}
dependencies {
// replace with the current version of the Android plugin
classpath 'com.android.tools.build:gradle:1.3.0'
// the latest version of the android-apt plugin
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
...
dependencies {
...
compile "org.parceler:parceler-api:1.0.3"
apt "org.parceler:parceler:1.0.3"
}

Categories

Resources