Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.process.ProcessException

JavaAndroidGradle

Java Problem Overview


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://[email protected]/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
    }
}

Java Solutions


Solution 1 - Java

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

Solution 2 - Java

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

Solution 3 - Java

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.

Solution 4 - Java

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.

Solution 5 - Java

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

Solution 6 - Java

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

Solution 7 - Java

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.

Solution 8 - Java

I've got this problem after including same classes twice

Solution 9 - Java

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" > }

Solution 10 - Java

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.

Solution 11 - Java

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.

Solution 12 - Java

I solved the same issue by removing:

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

and adding for each jar file:

compile files('libs/yourjarfile.jar')

Solution 13 - Java

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

Solution 14 - Java

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. :)

Solution 15 - Java

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'

Solution 16 - Java

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHuiView Question on Stackoverflow
Solution 1 - JavaBinod RokkaView Answer on Stackoverflow
Solution 2 - JavaNeteroView Answer on Stackoverflow
Solution 3 - JavaHarisewakView Answer on Stackoverflow
Solution 4 - JavasonphView Answer on Stackoverflow
Solution 5 - JavaHuiView Answer on Stackoverflow
Solution 6 - Javayabin yaView Answer on Stackoverflow
Solution 7 - JavacauldyclarkView Answer on Stackoverflow
Solution 8 - JavakonmikView Answer on Stackoverflow
Solution 9 - JavaAhmed FaisalView Answer on Stackoverflow
Solution 10 - JavaTommy ChanView Answer on Stackoverflow
Solution 11 - JavaBeemoView Answer on Stackoverflow
Solution 12 - JavaAyaz AlifovView Answer on Stackoverflow
Solution 13 - JavarobertView Answer on Stackoverflow
Solution 14 - JavatomisyournameView Answer on Stackoverflow
Solution 15 - JavaAbdul HaleemView Answer on Stackoverflow
Solution 16 - JavaJackView Answer on Stackoverflow