TransformException多个dex文件

时间:2017-02-21 16:56:51

标签: java android gradle

我用谷歌服务创建了一个应用程序,现在我想生成一个签名的apk。但是当我尝试创建这个apk时我得到了这个错误

  

错误:任务':app:transformClassesWithDexForRelease'执行失败。   com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:java.util.concurrent.ExecutionException:com.android.dex.DexException:多个dex文件定义Lcom / google / android /克/内部/ zzqv;

这是我的Gradle文件

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
    applicationId "com.xxx.xxx.xxx"
    minSdkVersion 18
    targetSdkVersion 25
    versionCode 5
    versionName "2.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
buildTypes {
    release {
        minifyEnabled false
        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.1.0'
compile project(':BaseGameUtils')
compile 'com.google.android.gms:play-services-ads:10.2.0'
compile 'com.google.android.gms:play-services-games:10.2.0'
compile 'com.google.android.gms:play-services-gcm:10.2.0'
compile 'cn.pedant.sweetalert:library:1.3'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.1@aar'
compile 'com.daimajia.androidanimations:library:1.1.3@aar'
testCompile 'junit:junit:4.12'
}

我已经尝试过Stackoverflow的一些解决方案但我的错误仍然出现。

我希望你们能帮助我解决我的问题

1 个答案:

答案 0 :(得分:0)

尝试在build.gradle中启用multidex:

defaultConfig {
    ...
    multiDexEnabled true
}

还要添加依赖项:

dependencies {
    compile 'com.android.support:multidex:1.0.0'
}

现在在您的Application类中:附加multidex

    public class MyApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

}

确保您在清单

中定义应用程序类