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://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
    }
}
Hui
  • 839
  • 1
  • 7
  • 11
  • You need to at least give us some background if there is to be any chance of assistance – DevDonkey Mar 07 '15 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 ?https://tainule@bitbucket.org/tainule/numad-huizhang.git – Hui Mar 07 '15 at 17:51
  • Please post the relevant parts of your code (specifically your build.gradle) file here, as part of your question. – yole Mar 07 '15 at 18:44
  • I did. Thanks for your help,Yole. – Hui Mar 07 '15 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 Oct 05 '15 at 08:47
  • can also try this one. compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } – Hui Oct 22 '15 at 12:01
  • I found this Git discussion helpful for me: https://github.com/facebook/rebound/issues/71 – Kalu Khan Luhar Mar 01 '17 at 06:37

16 Answers16

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

David Passmore
  • 6,089
  • 4
  • 46
  • 70
Binod Rokka
  • 869
  • 1
  • 5
  • 5
  • 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 Sep 04 '15 at 00: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 :( – Ahmed Faisal Dec 10 '15 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 – Ahmed Faisal Dec 10 '15 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

Netero
  • 3,761
  • 2
  • 29
  • 29
  • 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. – Muhammad Adil Oct 29 '15 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. – Divyanshu Negi Oct 31 '15 at 15:24
  • hi, where do i add this in? – Hanzawa Naoki Apr 13 '16 at 09:26
  • inside build.gradle file of your app module put it inside the android { ... } – Netero Apr 13 '16 at 09:37
  • thanks a lot! definitely this should be the correct answer. – vinicius gati Nov 21 '16 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.

Harisewak
  • 570
  • 6
  • 15
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.

sonph
  • 151
  • 4
11

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

Hui
  • 839
  • 1
  • 7
  • 11
  • 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 Jul 10 '15 at 21:35
  • 1
    in my case I already using "com.google.guava:guava:17.0" but problem is same. – CoDe Oct 06 '15 at 06: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

yabin ya
  • 7,283
  • 2
  • 11
  • 6
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.

David Passmore
  • 6,089
  • 4
  • 46
  • 70
cauldyclark
  • 75
  • 1
  • 3
6

I've got this problem after including same classes twice

konmik
  • 3,150
  • 19
  • 15
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" }

Ahmed Faisal
  • 4,397
  • 12
  • 45
  • 74
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.

Tommy Chan
  • 622
  • 7
  • 14
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.

Beemo
  • 441
  • 6
  • 18
  • 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 Jun 29 '15 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')
Ayaz Alifov
  • 8,334
  • 4
  • 61
  • 56
1

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

robert
  • 598
  • 1
  • 5
  • 12
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. :)

tomisyourname
  • 91
  • 1
  • 11
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'

jose920405
  • 7,982
  • 6
  • 45
  • 71
Abdul Haleem
  • 118
  • 1
  • 4
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.

Jack
  • 1,825
  • 3
  • 26
  • 43