71

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
    }
}
7
  • You need to at least give us some background if there is to be any chance of assistance
    – DevDonkey
    Commented Mar 7, 2015 at 17:31
  • Hi Matt, thanks for your reply. the possible reason may be that I add a external library module --endpoints. This is all I know. and the code have been uploaded to bitbucket , could you please help me with it ?[email protected]/tainule/numad-huizhang.git
    – Hui
    Commented Mar 7, 2015 at 17:51
  • Please post the relevant parts of your code (specifically your build.gradle) file here, as part of your question.
    – yole
    Commented Mar 7, 2015 at 18:44
  • I did. Thanks for your help,Yole.
    – Hui
    Commented Mar 7, 2015 at 19:21
  • i also got same error please help give some suggestions to solve it.am not uploading to any bitbuket or other.
    – Harsha
    Commented Oct 5, 2015 at 8:47

16 Answers 16

82

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

3
  • 1
    That's great, and it makes sense in my case, because we mistakenly check in the content of app/build to SVN, and that screwed up our builds locally.
    – Roberto
    Commented Sep 4, 2015 at 0:38
  • 2
    Doesn't work for me on AS 1.5 It rebuilds succesfully but I try to run it I get the same error as in the question above :( Commented Dec 10, 2015 at 17:35
  • 2
    Error:Execution failed for task ':ReliantApp:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_60\bin\java.exe'' finished with non-zero exit value 2 Commented Dec 10, 2015 at 17:36
45

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

5
  • 1
    this answer should marked as correct one. After trying all above issues this one worked for me. I know it must be bad solution but one who is using multiple android libraries he will face this issue and this solution will work for him/her. as those libraries use v4 or v7 support libraries. So in your project it repeats the library more than 1. Commented Oct 29, 2015 at 18:16
  • This worked for me, its the only solution which worked out of all the solutions. All other users check all other solutions, in case they does not work than this will surely work. Commented Oct 31, 2015 at 15:24
  • hi, where do i add this in? Commented Apr 13, 2016 at 9:26
  • inside build.gradle file of your app module put it inside the android { ... }
    – Netero
    Commented Apr 13, 2016 at 9:37
  • thanks a lot! definitely this should be the correct answer. Commented Nov 21, 2016 at 17:16
20

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
  • After adding this, I had to take out multiDexEnabled for mine to finally work.
    – JimJty
    Commented May 10, 2016 at 20:15
  • so your app runs without multiDex enabled?
    – Harisewak
    Commented May 11, 2016 at 10:23
  • yes, if I add multiDex enabled, I get some errors I haven't had time to look into further. I'm going take it for now, thanks for the tip.
    – JimJty
    Commented May 12, 2016 at 17:15
  • THANK YOU! I'm working on this problem for a whole day. But I only add javaMaxHeapSize "4g" to gradle and it works.
    – Kimi Chiu
    Commented Jul 2, 2016 at 4:45
15

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.

0
11

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

2
  • 2
    That's probably due to the mentioned method limit. The older version of Guava probably had less methods in it. Enabling multidex fixes this issue for real.
    – ByteWelder
    Commented Jul 10, 2015 at 21:35
  • 1
    in my case I already using "com.google.guava:guava:17.0" but problem is same.
    – CoDe
    Commented Oct 6, 2015 at 6:00
7

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

6

I've got this problem after including same classes twice

6

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.

4

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

3

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.

2

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.

1
  • 1
    Yep, this is a pretty bad solution (sorry for it). Although, I found another solution. There was a need to include RecyclerView into my project and it needed the support-v4 library. So I had to manually exclude support-v4 lib from all the dependency project and add it in my main gradle script (use gradle to list you the dependencies so you can see what else uses the support-v4 lib)
    – Beemo
    Commented Jun 29, 2015 at 15:04
2

I solved the same issue by removing:

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

and adding for each jar file:

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

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

1
  • Can you please tell how to clean ionic project using windows command?
    – Sachin HR
    Commented Feb 22, 2019 at 10:02
0

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

0

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'

0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.