错误:任务“:app:transformClassesWithDexForDebug"执行失败

Error:Execution failed for task #39;:app:transformClassesWithDexForDebug#39;(错误:任务“:app:transformClassesWithDexForDebug执行失败)
本文介绍了错误:任务“:app:transformClassesWithDexForDebug"执行失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

错误

错误:任务 ':app:transformClassesWithDexForDebug' 执行失败.com.android.build.transform.api.TransformException:com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程'命令'/usr/lib/jvm/java-8-oracle/bin/java'' 以非零退出值 1 结束

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,那么它会编译.但是,我无法调试我的应用程序.

While debugging, if I set minifyEnabled to true, then it compiles. However, then I cannot debug my application.

我检查了另一个问题:任务执行失败:app:transformClassesWithDexForDebug' 在为 Android 实施 Google 登录时,但只有一个答案,不幸的是,实施它并不能解决问题.

I checked this other question: Execution failed for task ':app:transformClassesWithDexForDebug' while implementing Google sign in for Android, but there is only one answer and implementing it does not resolve the issue unfortunately.

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

AFAIK, the error is caused due to addition of too many Gradle dependencies, but I may be wrong (I really hope to be wrong because all these packages are really important!).

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

Please help me to resolve this error. Much thanks!

推荐答案

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

Just correct Google play services dependencies:

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

You are including all play services in your project. Only add those you want.

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

For example , if you are using only maps and g+ signin, than change

 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'

来自文档:

在 6.5 之前的 Google Play 服务版本中,您必须编译整个 API 包到您的应用程序中.在某些情况下,这样做会使在您的应用程序中保持方法的数量变得更加困难(包括65,536 下的框架 API、库方法和您自己的代码)限制.

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.

从 6.5 版开始,您可以选择性地编译 Google Play服务 API 到您的应用程序中.例如,仅包含 GoogleFit 和 Android Wear API,在您的build.gradle 文件:
使用这些行编译 'com.google.android.gms:play-services:8.3.0'
:

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:

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

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

可在此处找到完整列表.

这篇关于错误:任务“:app:transformClassesWithDexForDebug"执行失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

IncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM(更新到 Android Build Tools 25.1.6 GCM/FCM 后出现 IncompatibleClassChangeError)
How to get current flavor in gradle(如何在 gradle 中获取当前风味)
How to fix quot;unexpected element lt;queriesgt; found in lt;manifestgt;quot; error?(如何修复“意外元素lt;查询gt;在“清单中找到错误?)
Multi flavor app based on multi flavor library in Android Gradle(基于 Android Gradle 中多风味库的多风味应用)
Android dependency has different version for the compile and runtime(Android 依赖在编译和运行时有不同的版本)
Transitive dependencies for local aar library(本地 aar 库的传递依赖)