0

i am trying to compile my android project using my Samsung/Virtual machine , but i am getting the following error:

    Error:Execution failed for task ':app:dexDebug'.
    > com.android.ide.common.process.ProcessException:         
    org.gradle.process.internal.ExecException: Process 'command
    '/Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/bin/java'' 
    finished with non-zero exit value 2

i couldn't find an answer anywhere, any thoughts please ?

Sam
  • 1
  • 1

4 Answers4

0

Try enabling multi dex file support in you gradle.

Add below code to your build.gradle

defaultConfig {        
    // Enabling multidex support.
    multiDexEnabled true
}
Rajan Kali
  • 12,627
  • 3
  • 25
  • 37
0

As far as I know this error isn't related to JDK or gradle itself, and could have many reasons such as:

  1. Exceeding 65k method limit.

You could try enabling multi dex support in gradle:

defaultConfig {        
    // Enabling multidex support.
    multiDexEnabled true
}

Or just try to minimize application by removing some unnecessary libraries.

  1. Some jar or library file is included in several places.

For this run following command in Android Studio:

gradlew -q dependencies yourProjectName_usually_app:dependencies --configuration compile

Search for duplications in listed dependences (marked with asterisk *) and remove it.

In this question there are more possibilities listed.

Community
  • 1
  • 1
Konrad 'Zegis'
  • 15,101
  • 1
  • 16
  • 18
0
classpath 'com.android.tools.build:gradle:1.3.0' -> Should be 1.3.1

buildToolsVersion '23.0.0' -> Should be '23.0.2'

Also add

 defaultConfig {        
// Enabling multidex support.
multiDexEnabled true

}

clean your code and build again

Android Geek
  • 8,956
  • 2
  • 21
  • 35
0
For me the problem was, i had put a unnecessary compile library code in build.gradle

dependencies {
    compile 'com.google.android.gms:play-services:7.5.0'
}
which was causing over 65k methods, so removed it,gradle sync, cleaned project, and then ran again and then this error stopped. I needed just maps and gcm so i put these lines and synced project

compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile 'com.google.android.gms:play-services-location:7.5.0'

Hi people i again encountered this problem and this time it was because of changing build tools version and it really required me to enable multidex..so i added these my app's build.gradle file..

defaultConfig {
    applicationId "com.am.android"
    minSdkVersion 13
    targetSdkVersion 23
    // Enabling multidex support.
    multiDexEnabled true
}

dexOptions {
    incremental true
    javaMaxHeapSize "2048M"
    jumboMode = true
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:multidex:1.0.1'
}
And create a class that extends Application class and include this method inside the class..

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}
also include in OnCreate method too

@Override
public void onCreate() {
    MultiDex.install(this);
    super.onCreate();
}
Rahil Ali
  • 957
  • 10
  • 25