serenei serenei - 7 months ago 377
Java Question

keep getting error Gradle Build failed with an exception : java.exe' finished with non-zero exit value 2 after adding library

I keep getting below error when i add new library into gradle:


Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_51\bin\java.exe'' finished with non-zero exit value 2


This is my gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
useLibrary 'org.apache.http.legacy'


defaultConfig {
applicationId "ir.whc.news"
minSdkVersion 14
targetSdkVersion 23

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}


dependencies {


testCompile 'junit:junit:4.12'
compile project(":volley")
compile project(":AndroidBootstrap")
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:support-annotations:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.shamanland:fonticon:0.1.9'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.weiwangcn.betterspinner:library-material:1.1.0'
compile 'com.joanzapata.pdfview:android-pdfview:1.0.4@aar'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.github.satyan:sugar:1.4'
provided 'org.apache.commons:commons-collections4:4.0'


}
apply plugin: 'com.google.gms.google-services'


In the accepted answer of this SO question, There's written that a conflict is the reason of this error. I do not know what is the conflict in my
gradle
dependency?

Answer

I suggest not to compile this as whole as it is, Most of the time this causes over 65K methods dex limit.

compile 'com.google.android.gms:play-services:8.3.0'

see here, Find out the specific one that you really need And use those as per your need for the specific purposes, and it seems you also forgot to add multiDexEnabled true.