Java finished with non-zero exit value 2 - Android Gradle

Maverick.pe picture Maverick.pe · Apr 20, 2015 · Viewed 133.6k times · Source

I'm getting this error executing my Android app (I cleaned it and then built it, but the error is still present)

  • Sync: OK
  • Make Project: OK
  • Clean: OK
  • Run: Error

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.7.0_25\bin\java.exe'' finished with non-zero exit value 2

My gradle file:

apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
    applicationId "com.rzr.rzevallosr.miappdepruebas"
    minSdkVersion 19
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

productFlavors {
}

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}
}

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

// This library handles authentication and authorization
compile 'com.spotify.sdk:spotify-auth:1.0.0-beta9@aar'
// This library handles music playback
compile 'com.spotify.sdk:spotify-player:1.0.0-beta9@aar'

compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.+'

compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'

compile files('libs/spotify-web-api-android-master-0.1.0.jar')
compile files('libs/okio-1.3.0.jar')
}

EDIT: I didn't see "compile fileTree(dir: 'libs', include: ['*.jar'])" it was compiling twice my libraries, so i just comment:

//compile 'com.squareup.retrofit:retrofit:1.9.0'
//compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
//compile 'com.squareup.okhttp:okhttp:2.2.0'

//compile files('libs/spotify-web-api-android-master-0.1.0.jar')
//compile files('libs/okio-1.3.0.jar')

and it works fine.

Answer

minhazur picture minhazur · Jun 7, 2015

This issue is quite possibly due to exceeding the 65K methods dex limit imposed by Android. This problem can be solved either by cleaning the project, and removing some unused libraries and methods from dependencies in build.gradle, OR by adding multidex support.

So, If you have to keep libraries and methods, then you can enable multi dex support by declaring it in the gradle config.

defaultConfig {        
    // Enabling multidex support.
    multiDexEnabled true
}

You can read more about multidex support and developing apps with more than 65K methods here.