Android Gradle Error “java finished with non-zero exit value 2”

Updated 18 December 2016

Save

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.

Explaination:

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.

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

 

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.

And create a class

 

that extends Application class

 

also add in OnCreate method too

 

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home