Error:Execution failed for task ':app:dexDebug

2019-01-01 16:08发布

问题:

Error:Execution failed for task \':app:dexDebug\'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process \'command \'C:\\Program Files\\Java\\jdk1.8.0_40\\bin\\java.exe\'\' finished with non-zero exit value 2

I searched all the similar questions and solutions, but they do not help. I hope experts like you come up.

The project code has been uploaded into bitbucket: https://tainule@bitbucket.org/tainule/numad-huizhang.git

I have two modules, app and endpoint. Below is from Module:app:

apply plugin: \'com.android.application\'

android {
    compileSdkVersion 21
    buildToolsVersion \"21.1.2\"

    defaultConfig {
        applicationId \"edu.neu.madcourse.huizhang1\"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 3
        versionName \"2.1\"
//        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile(\'proguard-android.txt\'), \'proguard-rules.pro\'

        }
    }
}

dependencies {


    compile fileTree(include: [\'*.jar\'], dir: \'libs\')
    compile \"com.android.support:appcompat-v7:21.0.+\"
    compile \'com.google.android.gms:play-services:+\'
    compile \'com.google.guava:guava:18.0\'
    compile \'com.google.code.gson:gson:1.7.2\'
    compile \'org.apache.httpcomponents:httpmime:4.4-beta1\'
    compile \'org.apache.httpcomponents:httpclient:4.4-beta1\'
    compile \'org.apache.httpcomponents:httpcore:4.4-beta1\'
    compile \'com.nostra13.universalimageloader:universal-image-loader:1.9.3\'
    compile project(path: \':endpoint\', configuration: \'android-endpoints\')
    compile files(\'src/main/res/libs/KeyValueAPI.jar\')

}

Below is from Module endpoint:

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath \'com.google.appengine:gradle-appengine-plugin:1.9.17\'
    }
}

repositories {
    mavenCentral();
}

apply plugin: \'java\'
apply plugin: \'war\'
apply plugin: \'appengine\'

sourceCompatibility = 1.7
targetCompatibility = 1.7

dependencies {
    appengineSdk \'com.google.appengine:appengine-java-sdk:1.9.8\'
    compile \'com.google.appengine:appengine-endpoints:1.9.8\'
    compile \'com.google.appengine:appengine-endpoints-deps:1.9.8\'
    compile \'javax.servlet:servlet-api:2.5\'
    compile \'com.googlecode.objectify:objectify:4.0b3\'
    compile \'com.ganyo:gcm-server:1.0.2\'
//        compile \'com.github.fengdai:alertdialogpro-theme-material:0.1.0\'

}

appengine {
    downloadSdk = true
    appcfg {
        oauth2 = true
    }
    endpoints {
        getClientLibsOnBuild = true
        getDiscoveryDocsOnBuild = true
    }
}

回答1:

It seems you have a jar file or a lib appearing multiple times.

So, remove the .jar file from the lib folder then:

Build > Rebuild



回答2:

I had the same problem error that is shown, i solve it by adding

defaultConfig {        
    // Enabling multidex support.
    multiDexEnabled true
}

I had this problem cause i exceeded the 65K methods dex limit imposed by Android i used so many libraries



回答3:

I am adding it so that someone in a similar situation might find it helpful.

So, even after multiDexEnabled = true I was getting the same error. I had no duplicate libraries. None of the above solutions worked. Upon reading the error log, I found OutOfMemError issue to be the primary reason and thought of changing the heap size somehow. Hence, this -

dexOptions {
        preDexLibraries = false
        javaMaxHeapSize \"4g\"
    }

Where \"4g\" means HeapSize of 4 GB. And it worked! I hope it does for you too.



回答4:

For me I had multiple versions of the same library included in /app/libs. I was using Parse and I had both ParseFacebookUtilsV3-1.9.0.jar and ParseFacebookUtilsV4-1.9.0.jar.

Deleting the V3 jar solves the problem.



回答5:

Finally I solved this problem by changing compile \'com.google.guava:guava:18.0 \' to compile \'com.google.guava:guava-jdk5:17.0\'



回答6:

three condition may cause this issue.

  1. differ module have differ jar
  2. in libs had contain jar,but in src alse add relevant source
  3. gradle repeat contain,eg:

    compile fileTree(include: [‘*.jar’], dir: ‘libs’)

    compile files(‘libs/xxx.jar’)

if you can read chinese ,read hereError:Execution failed for task \':app:dexDebug\'.> com.android.ide.common.process.ProcessException: o



回答7:

I\'ve got this problem after including same classes twice



回答8:

I encountered the same exact error message. I am not quite sure if my solution will solve also your issue.

In Project Structure (app) I changed the Compile SDK Version from API 22 to API 21 and changed Build Tools Version from 22.0.0 to 21.1.2.

When I downloaded the latest API 22 Adroid 5.1, every project I create is using this API and causes me the problem. Maybe, Android Team is looking for a fix for this one.



回答9:

I recently migrated one of our corporate projects from Eclipse to Android Studio.

We too got the below error during the migration:

Error:Execution failed for task \':appName:transformClassesWithDexForDebug\'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process \'command \'/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java\'\' finished with non-zero exit value 2

To resolve it, we had to do a few things:

  1. Remove/Update duplicate jars/files from libs

compile \'com.android.support:support-v4:23\' compile \'com.google.android.gms:play-services:9.0.0\'

to compile \'com.google.android.gms:play-services:9.0.0\'

  1. Set multiDexEnabled to True

defaultConfig { multiDexEnabled true }

  1. Increase the heap size:

dexOptions { incremental true javaMaxHeapSize \"4g\" }



回答10:

This could also be the case when you have too many object references. Take a look at the results from the build, esp in the task :dex:multiDebug:

trouble writing output: Too many method references: 67114; max is 65536.



回答11:

Try to put this line of code in your main projects gradle script:

configurations { all*.exclude group: \'com.android.support\', module: \'support-v4\' }

I have two libraries linked to my project and they where using \'com.android.support:support-v4:22.0.0\'.

Hope it helps someone.



回答12:

I solved the same issue by removing:

compile fileTree(include: [\'*.jar\'], dir: \'libs\')

and adding for each jar file:

compile files(\'libs/yourjarfile.jar\')


回答13:

Try to clean and rebuild the project. I had the absolutely same question, this solved it.



回答14:

I have the same issue, and solved by change the \'+\' to a exact number, like compile \"com.android.support:appcompat-v7:21.0.+\" to compile \"com.android.support:appcompat-v7:21.0.0\".

This works for me. :)



回答15:

I changed :

compile \'com.google.android.gms:play-services:9.0.0\'

compile \'com.google.android.gms:play-services-auth:9.0.0\'

to :

compile \'com.google.android.gms:play-services-maps:9.0.0\'

compile \'com.google.android.gms:play-services-auth:9.0.0\'



回答16:

I faced same issue when converting an eclipse project to Android studio.In my case i had the design lirary jar file in eclipse project and I have added dependency of the same in gradle caused the error.I solved it by deleting jar from libs.