Updated 18 December 2016
In this blog,
I have talked about the reason behind Android Gradle error.
“java finished with non-zero exit value 2”
This is a very general problem when we have used many libraries to build our android project.
So, I will give the answer and the some suggestions for avoiding this gradle error.
This issue is quite possibly due to exceeding the 65K methods dex limit imposed by Android.
And if you had put a unnecessary compile library code in build.gradle.
123 dependencies {compile 'com.google.android.gms:play-services:8.3.0'}
Which was causing over 65k methods, so removed it, used only neccessary compile library code gradle sync, cleaned project, and then ran again and then this error stopped. I needed just maps, analytics and gcm so i put these lines and synced project
12345 dependencies {compile 'com.google.android.gms:play-services-maps:8.3.0'compile 'com.google.android.gms:play-services-gcm:8.3.0'compile 'com.google.android.gms:play-services-analytics:8.3.0'}
After that your problem should be solved.
Note: If you want to count the total methods in your project then you can use the following link
http://inloop.github.io/apk-method-count/
By simply upload your apk file.
After all this If still your project is giving this error, So you have to enable the multidex in your project.
123456789101112131415 defaultConfig {// Enabling multidex .multiDexEnabled true}dexOptions {incremental truejavaMaxHeapSize "2048M"jumboMode = true}dependencies {compile fileTree(include: ['*.jar'], dir: 'libs')compile 'com.android.support:multidex:1.0.1'}
And create a class
12345 dependencies {compile 'com.google.android.gms:play-services-maps:8.3.0'compile 'com.google.android.gms:play-services-gcm:8.3.0'compile 'com.google.android.gms:play-services-analytics:8.3.0'}
that extends Application class
123456 @Overrideprotected void attachBaseContext(Context base) {super.attachBaseContext(base);//include this methodMultiDex.install(this);}
also add in OnCreate method too
12345 @Overridepublic void onCreate() {//include this methodMultiDex.install(this); super.onCreate();}
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.