1

我从命令行构建项目时遇到错误:

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 版本:3.5 Gradle 插件:3.5.1 Gradle:5.4.1

4

3 回答 3

2

(我不能添加评论,这需要50个声望,呵呵。)

正如 sgjesse@ 所提到的,使用最新的 R8 将显示具有无效属性的此类文件来自哪个。例如,https ://issuetracker.google.com/issues/142002569#comment4像:

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

除了您提到的属性之外,它还会提到哪个类文件或 jar 包含该类文件。然后,需要在负责该 jar 文件的相关编译器之一中对其进行修复。您能否告诉我们完整的错误消息,包括无效属性的“来源”?

于 2019-10-13T20:17:57.447 回答
0

这可能是由无效输入引起的。请查看https://issuetracker.google.com/142002569#comment2,并尝试使用更新的 R8 版本,在这种情况下提供更多信息(最新版本现在是 1.6.36)。

您可以通过将以下内容添加到顶级build.gradle文件来尝试 3.6 版本(无需升级 gradle 插件):

构建脚本 {

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

}

于 2019-10-11T07:29:43.600 回答
0

使用android.enableSeparateAnnotationProcessing=truegradle.properties我工作。

于 2020-08-18T08:12:43.000 回答