Is R8 not support applyMapping? - android

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.

Related

Gradle Error: Build failed with an exception, a problem occured while configuring project ':Demo'

While adding a project as a module
What went wrong:
It is too late to modify excludes
It has already been read to configure the project.
Consider either moving this call to be during evaluation, are using the variant API.
Steps followed: File -> Import module -> selec project file
Gradle Failed Exception
My project uses gRPC and this exception occurred.
Updating the version of Protobuf Plugin for Gradle from 0.8.13 to 0.9.1 resolved the error.
buildscript {
ext.versions = [
protobuf : [
plugin: "0.9.1",
],
]
dependencies {
classpath "com.google.protobuf:protobuf-gradle-plugin:$versions.protobuf.plugin"
}
}

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.

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

Build with R8 failing -> Error: Multiple annotations of type `dalvik.annotation.EnclosingClass`

I am getting the error on building the project from command line:
Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:131)
at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:118)
at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:102)
at com.android.build.gradle.internal.tasks.DexMergingTaskRunnable.run(DexMergingTask.kt:444)
... 22 more
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
at com.android.tools.r8.utils.t.a(:55)
at com.android.tools.r8.D8.run(:11)
at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:116)
... 24 more
Caused by: com.android.tools.r8.utils.AbortException: Error: Multiple annotations of type `dalvik.annotation.EnclosingClass`
at com.android.tools.r8.utils.Reporter.a(:21)
at com.android.tools.r8.utils.Reporter.a(:7)
at com.android.tools.r8.utils.t.a(:36)
... 26 more
Android Studio Version: 3.5
Gradle Plugin: 3.5.1
Gradle: 5.4.1
(I can't add a comment, which requires 50 reputations, huh.)
As mentioned by sgjesse#, using the latest R8 will show from which such a class file with invalid attributes came. For example, https://issuetracker.google.com/issues/142002569#comment4 like:
AGPBI: {"kind":"error","text":"A member class should be a (non-member) local class at the same time.\nThis is likely due to invalid EnclosingMethod and InnerClasses attributes:\n[enclosingClass: Lcom/tealium/library/c;, enclosingMethod: null]\n[access : 18, inner: Lcom/tealium/library/c$a;, outer: Lcom/tealium/library/b;, innerName: a]\n","sources":[{"file":"/Users/dps.developer/Documents/XXX_Repos/flagshipapp/libs/tealium.4.1.4c.jar"}],"tool":"R8"}
In addition to attributes you mentioned, it would mention which class file or jar includes that class file. Then, it would need to be fixed in one of the involved compilers responsible for that jar file. Could you let us know the full error message, including "sources" of invalid attributes?
This could be caused by invalid input. Please take a look at https://issuetracker.google.com/142002569#comment2, and try using a newer R8 version which will provide more info in this case (the latest version is 1.6.36 now).
You can try the 3.6 release (without upgrading gradle plugin) 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.36' // Must be before the Gradle Plugin for Android.
classpath 'com.android.tools.build:gradle:X.Y.Z' // Your current AGP (3.5.1 in this case) version.
}
}
use android.enableSeparateAnnotationProcessing=true in gradle.properties worked for me .

NoSuchMethodError HashCode.fromString when using com.android.tools.build:gradle:0.10.0

If you are using com.android.tools.build:gradle:0.10.0 and gradle 1.12, you might get this error.
FAILURE: Build failed with an exception.
What went wrong:
Failed to notify task execution graph listener.
java.lang.NoSuchMethodError: com.google.common.hash.HashCode.fromString(Ljava/lang/String;)Lcom/google/common/hash/HashCode;
java.lang.NoSuchMethodError: com.google.common.hash.HashCode.fromString(Ljava/lang/String;)Lcom/google/common/hash/HashCode;
HashCode.fromString in only in guava 15+ and somehow you may be pulling in an older version of guava. You should figure out why it is pulling in an old guava version. It might be some other dependency in your buildScript ( like CheckStyle 5.7 ).
As a workaround you can add an explicit dependency on guava 15.
buildscript {
....
dependencies {
classpath 'com.android.tools.build:gradle:0.10.0'
classpath 'com.google.guava:guava:15.0'

Categories

Resources