ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Android多个dex文件定义Lcom / google / android / gms / common / api / zza

2019-10-06 17:25:37  阅读:226  来源: 互联网

标签:android firebase android-gradle build android-multidex


构建项目并将应用程序部署到具有API级别22或25的模拟器可以,但是当我尝试构建APK或将应用程序部署到具有API级别16的真实设备时,我收到以下错误:

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
}

我的app 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'

你的app / build.gradle文件的to the bottom.

标签:android,firebase,android-gradle,build,android-multidex
来源: https://codeday.me/bug/20191006/1861629.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有