在Android Studio中构建APK文件时出错

时间:2017-10-06 12:23:18

标签: java android

我正在尝试为我的项目构建一个apk,但我遇到了这个错误并且

  

错误:任务执行失败   ':应用程序:transformClassesWithDexForDebug'。

     
    

com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:     java.util.concurrent.ExecutionException:com.android.dex.DexException:     多个dex文件定义Lcom / google / android / gms / internal / zzajl;

  

我还添加了 multiDexEnabled ,但仍然出现错误

  

错误:任务执行失败   ':应用程序:transformClassesWithJarMergingForDebug'。

     
    

com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:     COM /谷歌/机器人/克/内部/ zzaix.class

  

以下是我的 Build.gradle 文件

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "in.package.name"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true


    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }


}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.android.gms:play-services-ads:11.0.1'
    testCompile 'junit:junit:4.12'
    // Adding support library for this demo app
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.google.firebase:firebase-database:9.6.1'


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

请建议我一些解决方案 谢谢

2 个答案:

答案 0 :(得分:3)

使用 SAME 版本

compile 'com.google.android.gms:play-services-ads:11.0.1'
 compile 'com.google.firebase:firebase-database:11.0.1'

然后 Clean-Rebuild and Restart IDE

答案 1 :(得分:0)

首先尝试清理项目 - ./gradlew clean