Android 多个 dex 文件定义 Lcom/google/android/gms/common/api/zza
Android Multiple dex files define Lcom/google/android/gms/common/api/zza
使用 API 级别 22 或 25 构建项目并将应用程序部署到模拟器没问题,但是当我尝试使用 API 级别 16 构建 APK 或将应用程序部署到我的真实设备时,我得到以下错误:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/common/api/zza;
我的项目build.gradle文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'me.tatarka:gradle-retrolambda:3.3.0-beta4'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我的应用程序 build.gradle 文件:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "<aplication id here>"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
final SUPPORT_LIBRARY_VERSION = '25.0.1'
final DAGGER_VERSION = '2.4'
final BUTTERKNIFE_VERSION = '8.0.1'
final TIMBER_VERISON = '4.3.0'
final LEAKCANARY_VERSION = '1.4'
final FIREBASE_VERSION = '10.0.0'
final FIREBASE_UI_VERSION = '1.0.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:design:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:cardview-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:support-v4:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:support-vector-drawable:$SUPPORT_LIBRARY_VERSION"
compile "com.google.dagger:dagger:$DAGGER_VERSION"
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
compile "com.google.firebase:firebase-database:$FIREBASE_VERSION"
compile "com.firebaseui:firebase-ui-database:$FIREBASE_UI_VERSION"
compile "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION"
apt "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION"
compile "com.jakewharton.timber:timber:$TIMBER_VERISON"
debugCompile "com.squareup.leakcanary:leakcanary-android:$LEAKCANARY_VERSION"
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
}
注意: 如果我将 "multiDexEnabled true" 行添加到我的 defaultConfig,我将收到以下错误:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/common/api/zza.class
移动这个:
apply plugin: 'com.google.gms.google-services'
to the bottom 您的 app/build.gradle 文件。
虽然我有同样的错误,但上面的解决方案对我不起作用。我设法通过将我的 firebase-ui 库版本从 2.0.0 降级到 1.2.0 并将以下内容添加到项目级别 build.gradle 文件来解决错误:
allprojects {
repositories {
jcenter()
// Add the following
maven {
url 'https://maven.fabric.io/public'
}
}
}
对我来说,我只是将 firebase 库更新到最新版本,它就起作用了
这可能不适用于原始问题,但以防万一它对其他人有帮助。我 运行 在我的 ionic v1 项目中遇到了这个错误。我不使用 firebase,但我确实用 修复了它(对我来说很容易修复 - 将所有 google 服务版本标准化为在 android/project.properties 中相同)
使用 API 级别 22 或 25 构建项目并将应用程序部署到模拟器没问题,但是当我尝试使用 API 级别 16 构建 APK 或将应用程序部署到我的真实设备时,我得到以下错误:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/common/api/zza;
我的项目build.gradle文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'me.tatarka:gradle-retrolambda:3.3.0-beta4'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我的应用程序 build.gradle 文件:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "<aplication id here>"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
final SUPPORT_LIBRARY_VERSION = '25.0.1'
final DAGGER_VERSION = '2.4'
final BUTTERKNIFE_VERSION = '8.0.1'
final TIMBER_VERISON = '4.3.0'
final LEAKCANARY_VERSION = '1.4'
final FIREBASE_VERSION = '10.0.0'
final FIREBASE_UI_VERSION = '1.0.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:design:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:cardview-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:support-v4:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:support-vector-drawable:$SUPPORT_LIBRARY_VERSION"
compile "com.google.dagger:dagger:$DAGGER_VERSION"
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
compile "com.google.firebase:firebase-database:$FIREBASE_VERSION"
compile "com.firebaseui:firebase-ui-database:$FIREBASE_UI_VERSION"
compile "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION"
apt "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION"
compile "com.jakewharton.timber:timber:$TIMBER_VERISON"
debugCompile "com.squareup.leakcanary:leakcanary-android:$LEAKCANARY_VERSION"
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
}
注意: 如果我将 "multiDexEnabled true" 行添加到我的 defaultConfig,我将收到以下错误:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/common/api/zza.class
移动这个:
apply plugin: 'com.google.gms.google-services'
to the bottom 您的 app/build.gradle 文件。
虽然我有同样的错误,但上面的解决方案对我不起作用。我设法通过将我的 firebase-ui 库版本从 2.0.0 降级到 1.2.0 并将以下内容添加到项目级别 build.gradle 文件来解决错误:
allprojects {
repositories {
jcenter()
// Add the following
maven {
url 'https://maven.fabric.io/public'
}
}
}
对我来说,我只是将 firebase 库更新到最新版本,它就起作用了
这可能不适用于原始问题,但以防万一它对其他人有帮助。我 运行 在我的 ionic v1 项目中遇到了这个错误。我不使用 firebase,但我确实用