android - 错误 :Execution failed for task ':app:transformClassesWithDexForDebug'

标签 android android-studio android-gradle-plugin android-multidex

错误

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 1

我的应用 gradle 文件:

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

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        applicationId 'Hidden application ID'
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        disable 'InvalidPackage'
    }
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
    productFlavors {
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'com.facebook.android:facebook-android-sdk:4.7.0'
    compile 'com.googlecode.libphonenumber:libphonenumber:7.2.1'
    compile 'com.getbase:floatingactionbutton:1.10.1'
    compile 'com.android.support:preference-v7:23.1.1'
}

在调试时,如果我将 minifyEnabled 设置为 true,那么它会编译。但是,我无法调试我的应用程序。

我检查了另一个问题:Execution failed for task ':app:transformClassesWithDexForDebug' while implementing Google sign in for Android ,但只有一个答案,不幸的是,实现它并不能解决问题。

AFAIK,错误是由于添加了太多 Gradle 依赖项引起的,但我可能错了(我真的希望是错的,因为所有这些包都非常重要!)。

请帮我解决这个错误。非常感谢!

最佳答案

只需更正 Google Play 服务依赖项:

您的项目中包含所有播放服务。只添加你想要的。

例如,如果您只使用 map 和 g+ 登录,则更改

 compile 'com.google.android.gms:play-services:8.1.0'

compile 'com.google.android.gms:play-services-maps:8.1.0'
compile 'com.google.android.gms:play-services-plus:8.1.0'

来自文档:

In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.

From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:
compile 'com.google.android.gms:play-services:8.3.0'
with these lines:

compile 'com.google.android.gms:play-services-fitness:8.3.0'
compile 'com.google.android.gms:play-services-wearable:8.3.0'

Whole list can be found here .

关于android - 错误 :Execution failed for task ':app:transformClassesWithDexForDebug' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33717886/

相关文章:

android - APK 大小比预期大 - android studio

android - 修改之前如何在 AsyncTask 中使用变量?

java - context.getFilesDir() 时文件目录不存在

android - 应用程序初始化很慢 : FirebaseApp initialization unsuccessful

android - 有没有办法在 android studio 中找到所有的 Log.d() 行

带有顶级异常的Android Studio gradle错误

android - 如何/在哪里存储 Android 上的刷新 token ?

android - 如何在 Android Studio 中添加测试文件夹

java - 发生评估根项目> com.android.application找不到插件

android - 降级 Android Studio 导致不可恢复的错误