Android Multiple dex files define Lcom/google/android/gms/common/api/zza

早过忘川 提交于 2019-11-30 02:44:21

问题


Building project and deploying app to the emulator with API level 22 or 25 goes ok, but when i try to build APK or deploy app to my real device with API level 16 i get the following error:

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;

My project build.gradle file:

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
}

My app build.gradle file:

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

Note: if i add the "multiDexEnabled true" line to my defaultConfig i'll get the following error:

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

回答1:


Move this:

apply plugin: 'com.google.gms.google-services'

to the bottom of your app/build.gradle file.




回答2:


Although I had the same error but the above solution did not work for me. I managed to solve the error by downgrading my firebase-ui library version from 2.0.0 to 1.2.0 and added the following to Project level build.gradle file:

allprojects {
    repositories {
        jcenter()

        // Add the following
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
}



回答3:


for me, I just update firebase library to the newest version and it just worked




回答4:


This probably doesn't apply to the original question, but in case it helps someone else. I ran into this error with my ionic v1 project. I don't use firebase, but I did fix it with this answer (easy fix for me - standardize all google service versions to be the same in android/project.properties)



来源:https://stackoverflow.com/questions/40877434/android-multiple-dex-files-define-lcom-google-android-gms-common-api-zza

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!