【问题标题】:Error:Execution failed for task ':app:transformClassesWithDexForRelease' - Android studio错误:任务':app:transformClassesWithDexForRelease'的执行失败 - Android Studio
【发布时间】:2017-04-07 09:27:07
【问题描述】:

我已经使用 android studio 成功创建了一个 android 应用程序,当我遇到 android 模拟器或连接到开发机器的设备时工作正常,但是当我尝试从 build/outputs/apk 安装 apk 时,应用程序在打开时崩溃.我也尝试从构建的android studio生成签名的apk - >生成签名的apk(发布和调试)但它无法生成apk并出现以下错误:

Error:Execution failed for task ':app:transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lorg/intellij/lang/annotations/Identifier;

我的build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.aitrich.android.modern.photo"
        minSdkVersion 14
        targetSdkVersion 25
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'org.greenrobot.greendao'

ext {
    supportLibraryVersion = '25.0.1'
    playServicesVersion = '9.0.2'
    retrofitVersion = '2.1.0'
}

greendao {
    schemaVersion 1
}

apt {
    arguments {
        stagGeneratedPackageName "com.aitrich.android.modern.stag.generated"
        stagDebug true
    }
}


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'
    })
    testCompile 'junit:junit:4.12'

    compile "com.android.support:design:$supportLibraryVersion"
    compile "com.android.support:support-v13:$supportLibraryVersion"
    compile "com.android.support:cardview-v7:$supportLibraryVersion"
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'org.greenrobot:greendao:3.2.0'
    compile 'com.jakewharton:butterknife:8.4.0'
    compile 'com.intuit.sdp:sdp-android:1.0.3'
    compile 'me.zhanghai.android.materialprogressbar:library:1.3.0'
    compile 'com.mobsandgeeks:android-saripaar:2.0.3'
    compile "com.squareup.retrofit2:retrofit:$retrofitVersion"
    compile "com.squareup.retrofit2:converter-gson:$retrofitVersion"
    compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.vimeo.stag:stag-library:2.0.2'
    compile 'com.github.hotchemi:permissionsdispatcher:2.2.0'
    compile 'com.tapadoo.android:alerter:1.0.6'
    compile 'ch.halcyon:squareprogressbar:1.6.0'
    compile 'com.yalantis:ucrop:2.2.0'
    compile 'com.yalantis:ucrop:2.2.0-native'
    compile 'com.evernote:android-job:1.1.8'
    compile('com.github.silvestrpredko:dot-progress-bar:1.1') {
        exclude group: 'com.android.support', module: 'appcompat-v7'
    }
    compile('com.github.StevenDXC:DxLoadingButton:1.5') {
        exclude group: 'com.android.support', module: 'appcompat-v7'
    }
    compile('com.redmadrobot:chronos:1.0.7') {
        exclude module: 'eventbus:2.4.0'
    }
    compile ('co.infinum:materialdatetimepicker-support:3.1.3') {
        exclude group: 'com.android.support', module: 'design'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude group: 'com.android.support', module: 'support-v13'
    }
    compile 'com.android.support:multidex:1.0.1'


    apt 'com.jakewharton:butterknife-compiler:8.4.0'
    apt 'com.vimeo.stag:stag-library-compiler:2.0.2'
    apt 'com.github.hotchemi:permissionsdispatcher-processor:2.2.0'
}

【问题讨论】:

    标签: android android-studio gradle


    【解决方案1】:

    编辑:

    请检查您是否有这两个库通用:

     compile 'com.yalantis:ucrop:2.2.0'
     compile 'com.yalantis:ucrop:2.2.0-native'
    

    删除其中一个并检查您需要哪一个。

    检查this 答案是否有multidex 问题。那个帮助我解决了这个问题。

    您的 logcat 似乎清楚地显示了注释标识符 DexException: Multiple dex files define Lorg/intellij/lang/annotations/Identifier。你应该remove这一行支持-annotations:

     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
    

    此外,如果您使用的是这样的 google play services 捆绑包:compile 'com.google.android.gms:play-services:8.1.0

    为所有库分别更改为以下 gms

    compile 'com.google.android.gms:play-services-location:8.1.0'
     compile 'com.google.android.gms:play-services-base:8.1.0'
     compile 'com.google.android.gms:play-services-analytics:8.1.0'
     compile 'com.google.android.gms:play-services-maps:8.1.0'
    
     compile "com.google.android.gms:play-services-gcm:8.1.0'    //
    

    gcm 推送通知

    【讨论】:

    • 感谢您的快速响应,但不幸的是,如果上述依赖项在我的项目中,我没有使用任何。
    • @darwin 编辑后的 ​​gradle 文件中的 dex 选项和打包选项在哪里
    • 对不起,我忘记了,但添加 dexOptions { //incremental = true; 后仍然存在问题preDexLibraries = false javaMaxHeapSize "4g" } packagingOptions { exclude 'META-INF/NOTICE.txt' // 不会包含 NOTICE 文件 exclude 'META-INF/LICENSE.txt' // 不会包含 LICENSE 文件 }
    • @darwin 在清单中的应用程序元素中添加了这一行? android:name="android.support.multidex.MultiDexApplication"
    • 还是同样的问题
    【解决方案2】:

    尝试启用 multidex 。在应用级别 build.gradle 写下这些行

       android {
    ...
       defaultConfig {
           ...
           // Enabling multidex support.
           multiDexEnabled true
           ...
       }
    
    ...
    }
    dependencies {
    ...
       compile 'com.android.support:multidex:1.0.1'
    ...
    }
    

    查看this了解更多信息

    【讨论】:

    • 我将发布我的 gradle 文件,请检查更新的问题
    猜你喜欢
    • 2016-06-23
    • 2018-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-09
    相关资源
    最近更新 更多