1

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

sgjesse
  • 3,793
  • 14
  • 17

3 Answers3

2

(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?

jsjeon
  • 21
  • 1
0

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

}

sgjesse
  • 3,793
  • 14
  • 17
  • 1
    Now I am facing following issue : A member class should be a (non-member) local class at the same time. This is likely due to invalid EnclosingMethod and InnerClasses attributes: [enclosingClass: Lcom/loc/p;, enclosingMethod: null] [access : 9, inner: Lcom/loc/p$a;, outer: Lcom/loc/o;, innerName: a] – Shashank Srivastava Oct 12 '19 at 02:00
  • Did you see the answer from @jsjeon about getting the information about the class file which is the root cause of this issue? – sgjesse Oct 17 '19 at 10:21
  • @ShashankSrivastava i am facing same issue how you solve that ? – h_patel Aug 10 '20 at 08:50
  • @h_patel it was the issue with R8 version, try playing with the R8 version – Shashank Srivastava Aug 10 '20 at 18:26
0

use android.enableSeparateAnnotationProcessing=true in gradle.properties worked for me .

h_patel
  • 744
  • 5
  • 16