我有一个构建得很好的应用程序,但是当我尝试更新一些 Gradle 依赖项时就开始失败,而主要的嫌疑人是 firebase。
这是我遇到的错误:
Caused by: com.android.builder.multidex.D8MainDexList$MainDexListException: com.android.tools.r8.errors.CompilationError: Program type already present: com.google.android.gms.internal.measurement.zzdz
这是我项目的 git diff,显示了 Gradle 文件中的差异:
diff --git a/android/build.gradle b/android/build.gradle
index 9f63f745..08fda2eb 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -81,8 +81,8 @@ dependencies {
implementation "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
implementation "com.android.billingclient:billing:$playBillingLibVersion"
- implementation "com.google.firebase:firebase-core:16.0.3"
- implementation "com.google.firebase:firebase-ads:15.0.1"
+ implementation "com.google.firebase:firebase-core:16.0.5"
+ implementation "com.google.firebase:firebase-ads:17.0.0"
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
implementation fileTree(include: ['*.jar'], dir: 'libs')
diff --git a/android_common/build.gradle b/android_common/build.gradle
index f8224509..3a5d45e1 100644
--- a/android_common/build.gradle
+++ b/android_common/build.gradle
@@ -19,7 +19,7 @@ android {
androidTest.setRoot('tests')
}
defaultConfig {
- minSdkVersion 15
+ minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
@@ -65,8 +65,8 @@ dependencies {
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
implementation "com.android.billingclient:billing:$playBillingLibVersion"
- implementation "com.google.firebase:firebase-core:16.0.3"
- implementation "com.google.firebase:firebase-ads:15.0.1"
+ implementation "com.google.firebase:firebase-core:16.0.5"
+ implementation "com.google.firebase:firebase-ads:17.0.0"
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
diff --git a/android_instant_feature/build.gradle b/android_instant_feature/build.gradle
index 30431c11..17c4ef27 100644
--- a/android_instant_feature/build.gradle
+++ b/android_instant_feature/build.gradle
@@ -18,7 +18,7 @@ android {
defaultConfig {
versionCode 4031
versionName "4.1.2.1i"
- minSdkVersion 15
+ minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true
}
@@ -77,8 +77,8 @@ dependencies {
api 'com.android.support:multidex:1.0.3'
implementation "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
- implementation "com.google.firebase:firebase-core:16.0.3"
- implementation 'com.google.android.gms:play-services-instantapps:16.0.0'
+ implementation "com.google.firebase:firebase-core:16.0.5"
+ implementation 'com.google.android.gms:play-services-instantapps:16.0.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
diff --git a/core/build.gradle b/core/build.gradle
index dd2640cf..5694a1da 100644
--- a/core/build.gradle
+++ b/core/build.gradle
@@ -15,7 +15,7 @@ dependencies {
compile group: 'commons-io', name: 'commons-io', version: '2.6'
// https://mvnrepository.com/artifact/commons-codec/commons-codec
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
- compile 'com.google.code.gson:gson:2.8.2'
+ compile 'com.google.code.gson:gson:2.8.5'
compile group: 'org.apache.commons', name: 'commons-text', version: '1.2'
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
compile group: 'org.jetbrains', name: 'annotations', version: '16.0.1'
@@ -23,7 +23,7 @@ dependencies {
implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
testCompile 'junit:junit:4.12'
- testCompile 'org.mockito:mockito-core:2.7.22'
+ testCompile 'org.mockito:mockito-core:2.8.9'
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '1.7.3'
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '1.7.3'
}
请注意,其中一些更改(例如 minSDKVersion)可以作为错误的来源而被丢弃。它似乎很可能与 firebase 有关。为什么?好吧,除其他事项外,Stackoverflow 中还有其他问题就是这种情况,但是所有这些中提出的解决方案是将 firebase 依赖项更新到最新版本,但是将 firebase 依赖项更新到最新版本似乎是这样导致我的项目出现问题!使用旧版本它构建得很好。
这些是涉及到的Gradle脚本的内容(我已经将实际的applicationId替换为'com.myapp.id')
:核心
apply plugin: "java"
targetCompatibility = 1.8
sourceCompatibility = 1.8
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.java.srcDirs = ["src/main"]
sourceSets.test.java.srcDirs = ["src/test"]
dependencies {
compile 'commons-io:commons-io:2.6'
compile 'commons-codec:commons-codec:1.11'
compile 'com.google.code.gson:gson:2.8.5'
compile 'org.apache.commons:commons-text:1.2'
compile 'org.apache.commons:commons-collections4:4.1'
compile 'org.jetbrains:annotations:16.0.1'
compile "com.badlogicgames.gdx:gdx:1.9.9-SNAPSHOT"
compile "com.badlogicgames.gdx:gdx-freetype:1.9.9-SNAPSHOT"
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.8.9'
testCompile 'org.powermock:powermock-api-mockito2:1.7.3'
testCompile 'org.powermock:powermock-module-junit4:1.7.3'
}
repositories {
mavenCentral()
}
jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
:android_common
apply plugin: "com.android.feature"
configurations { natives }
android {
baseFeature true
compileSdkVersion 28
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
androidTest.setRoot('tests')
}
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
sourceSets {
all {
manifest.srcFile "AndroidManifest.xml"
}
}
multiDexEnabled true
}
buildTypes {
release {
setMinifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '28.0.2'
lintOptions {
abortOnError false
}
dexOptions {
jumboMode true
}
}
dependencies {
application project(':android')
feature project(':android_instant_feature')
api project(':core')
api 'com.android.support:multidex:1.0.3'
implementation "com.badlogicgames.gdx:gdx-backend-android:1.9.9-SNAPSHOT"
natives "com.badlogicgames.gdx:gdx-platform:1.9.9-SNAPSHOT:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:1.9.9-SNAPSHOT:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:1.9.9-SNAPSHOT:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-platform:1.9.9-SNAPSHOT:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:1.9.9-SNAPSHOT:natives-x86_64"
implementation "com.badlogicgames.gdx:gdx-freetype:1.9.9-SNAPSHOT"
natives "com.badlogicgames.gdx:gdx-freetype-platform:1.9.9-SNAPSHOT:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-freetype-platform:1.9.9-SNAPSHOT:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:1.9.9-SNAPSHOT:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:1.9.9-SNAPSHOT:natives-x86"
natives "com.badlogicgames.gdx:gdx-freetype-platform:1.9.9-SNAPSHOT:natives-x86_64"
implementation "com.android.billingclient:billing:dp-1"
implementation "com.google.firebase:firebase-core:16.0.5"
implementation "com.google.firebase:firebase-ads:17.0.0"
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.guava:guava:24.0-android'
}
task copyAndroidNatives() {
file("libs/armeabi/").mkdirs();
file("libs/armeabi-v7a/").mkdirs();
file("libs/arm64-v8a/").mkdirs();
file("libs/x86_64/").mkdirs();
file("libs/x86/").mkdirs();
configurations.natives.files.each { jar ->
def outputDir = null
if (jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
if (jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
if (jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
if (jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
if (outputDir != null) {
copy {
from zipTree(jar)
into outputDir
include "*.so"
}
}
}
}
:安卓
apply plugin: "com.android.application"
apply plugin: 'io.fabric' // Needed by crashlytics. DO NOT REMOVE.
android {
buildToolsVersion "28.0.2"
compileSdkVersion 28
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ["${project(':android_common').projectDir}/res"]
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
androidTest.setRoot('tests')
}
defaultConfig {
applicationId "com.myapp.id"
versionCode 4032
versionName "4.1.2.1"
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true
}
dexOptions {
jumboMode true
}
// Proguard configuration
buildTypes {
release {
//minifyEnabled true will turn proguard ON
minifyEnabled true
//proguardFiles let you add your own proguard rules ('proguard-project.txt') in this case, as its already created by gdx-setup
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
productFlavors {
}
lintOptions {
abortOnError false
}
}
task importPuzzles(type: Exec) {
// TODO
}
task run(type: Exec) {
def path
def localProperties = project.file("../local.properties")
if (localProperties.exists()) {
Properties properties = new Properties()
localProperties.withInputStream { instr ->
properties.load(instr)
}
def sdkDir = properties.getProperty('sdk.dir')
if (sdkDir) {
path = sdkDir
} else {
path = "$System.env.ANDROID_HOME"
}
} else {
path = "$System.env.ANDROID_HOME"
}
def adb = path + "/platform-tools/adb"
commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.myapp.id/com.myapp.id.AndroidLauncher'
}
dependencies {
implementation project(":android_common")
api 'com.android.support:multidex:1.0.3'
implementation "com.badlogicgames.gdx:gdx-backend-android:1.9.9-SNAPSHOT"
implementation "com.badlogicgames.gdx:gdx-freetype:1.9.9-SNAPSHOT"
implementation "com.android.billingclient:billing:dp-1"
implementation "com.google.firebase:firebase-core:16.0.5"
implementation "com.google.firebase:firebase-ads:17.0.0"
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
implementation fileTree(include: ['*.jar'], dir: 'libs')
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
:android_instant_feature
apply plugin: "com.android.feature"
android {
// baseFeature true
buildToolsVersion "28.0.2"
compileSdkVersion 28
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ["${project(':android_common').projectDir}/res"]
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}
defaultConfig {
versionCode 4031
versionName "4.1.2.1i"
minSdkVersion 16
targetSdkVersion 28
multiDexEnabled true
}
dexOptions {
jumboMode true
}
// Proguard configuration
buildTypes {
release {
//minifyEnabled true will turn proguard ON
// minifyEnabled true
//proguardFiles let you add your own proguard rules ('proguard-project.txt') in this case, as its already created by gdx-setup
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
debug {}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
productFlavors {
}
lintOptions {
abortOnError false
}
}
task run(type: Exec) {
def path
def localProperties = project.file("../local.properties")
if (localProperties.exists()) {
Properties properties = new Properties()
localProperties.withInputStream { instr ->
properties.load(instr)
}
def sdkDir = properties.getProperty('sdk.dir')
if (sdkDir) {
path = sdkDir
} else {
path = "$System.env.ANDROID_HOME"
}
} else {
path = "$System.env.ANDROID_HOME"
}
def adb = path + "/platform-tools/adb"
commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.myapp.id/com.myapp.id.AndroidLauncher'
}
dependencies {
implementation project(":android_common")
api 'com.android.support:multidex:1.0.3'
implementation "com.badlogicgames.gdx:gdx-backend-android:1.9.9-SNAPSHOT"
implementation "com.badlogicgames.gdx:gdx-freetype:1.9.9-SNAPSHOT"
implementation "com.google.firebase:firebase-core:16.0.5"
implementation 'com.google.android.gms:play-services-instantapps:16.0.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
最后,这是我的项目结构。与 android 相关的最相关部分是顶部的部分。下面我只是展示它与核心模块的关系。
这是一款 libGDX 游戏,我正在使用 IntelliJ Idea,尽管这无关紧要,因为我在命令行中使用 ./gradlew build 时遇到了这些错误。
编辑:我按照 TWL 的建议将 firebase-core 从 16.0.5 降级到 16.0.4 并且它有效,所以我认为这是一个可以接受的解决方法,至少在 firebase 人员发布 firebase-core 16.0.6 左右时实际上与 firebase-ads 17.0.0 兼容。问题似乎是 firebase-ads 17.0.0 依赖于导致错误的旧版本库。
查看这些依赖项输出:
这是我使用 firebase-core 16.0.4 得到的结果:
$ ./gradlew android_common:dependencies | grep measurement-base
<-------------> 0% EXECUTING [0s]
> :android_common:dependencies
| | | +--- com.google.android.gms:play-services-measurement-base:16.0.3
| | | | +--- com.google.android.gms:play-services-measurement-base:16.0.3
| | +--- com.google.android.gms:play-services-measurement-base:16.0.3
| +--- com.google.android.gms:play-services-measurement-base:16.0.3
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3
| | | +--- com.google.android.gms:play-services-measurement-base:16.0.3
| | | | +--- com.google.android.gms:play-services-measurement-base:16.0.3
| | +--- com.google.android.gms:play-services-measurement-base:16.0.3
| +--- com.google.android.gms:play-services-measurement-base:16.0.3
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3
| | | +--- com.google.android.gms:play-services-measurement-base:16.0.3
| | | | +--- com.google.android.gms:play-services-measurement-base:16.0.3
| | +--- com.google.android.gms:play-services-measurement-base:16.0.3
| +--- com.google.android.gms:play-services-measurement-base:16.0.3
...(等等,所有 16.0.3 直接向前)
这是针对 firebase-core 16.0.5 的:
$ ./gradlew android_common:dependencies | grep measurement-base
<-------------> 0% EXECUTING [1s]
> :android_common:dependencies > Resolve dependencies of :android_common:releaseUnitTestRuntimeClasspath
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4
| | | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3 -> 16.0.4 (*)
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4
| | | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3 -> 16.0.4 (*)
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4
| | | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3 -> 16.0.4 (*)
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4
| | | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3 -> 16.0.4 (*)
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4
| | | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3 -> 16.0.4 (*)
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4
| | | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3 -> 16.0.4 (*)
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4
| | | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3 -> 16.0.4 (*)
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4
| | | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3 -> 16.0.4 (*)
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4
| | | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3 -> 16.0.4 (*)
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4
| | | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3 -> 16.0.4 (*)
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4
| | | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3 -> 16.0.4 (*)
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4
| | | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3 -> 16.0.4 (*)
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4
| | | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3 -> 16.0.4 (*)
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4
| | | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | | \--- com.google.android.gms:play-services-measurement-base:16.0.3 -> 16.0.4 (*)
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4
| | | | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.4] -> 16.0.4 (*)
如您所见,有一些条目,例如“com.google.android.gms:play-services-measurement-base:16.0.3 -> 16.0.4 (*)”,尽管我并不精通解释这些输出,我认为是问题的原因。
最佳答案
好吧,因为所有评论都已转移到聊天中,而且我的临时解决方法也在那里,那么就在这里:
您的错误消息使我搜索到 com.android.tools.r8.errors.CompilationError: Program type already present: androidx.annotation.AnimRes
Caused by: com.android.builder.multidex.D8MainDexList$MainDexListException: com.android.tools.r8.errors.CompilationError: Program type already present: ___
该错误表明某处存在重复的依赖项,该依赖项正在运行两个不同的版本。然后目标是运行 ./gradlew app:dependencies
来生成依赖树/列表以查找 com.google.android.gms.internal.measurement.zzdz
。问题是这个被混淆了,是内部私有(private)包,所以不会直接在列表中找到,但是关键字measurement
是一个提示。
这让我注意到 core
和 ads
有类似的东西:play-services-measurement-api:[16.0.3] -> 16.0。 3 (*)
和 play-services-measurement-sdk-api:16.0.2
。通过测试,我发现了两种解决方法:
- 将
com.google.firebase:firebase-core:16.0.5
降级为16.0.4
- 添加
exclude group: 'com.google.android.gms', module: 'play-services-measurement-sdk-api'
到ads
依赖项<
第一个 选项可能更安全,因为重新运行 ./gradlew app:dependencies
表明 play-services-measurement-api
和 play-services-measurement-sdk-api
现在都是 16.0.2
。
而且我确信 Google/Firebase 知道这一点,因为我确实在 https://issuetracker.google.com/issues/119213680 上找到了另一个提及它的地方。翻译过来就是:错误是类zzdz的重复,zzdz类的存在状态转移如下。因此请注意 play-services-measurement-sdk-api
可能会遇到其他 Firebase/GMS 库的问题。应该有一个即将更新的修复程序。
*请注意,即使切换到 "com.google.firebase:firebase-ads:17.1.0"
仍会导致此错误。
关于java - 更新 Gradle 依赖项后构建错误。嫌疑人 #1 是 firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53208575/