Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
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.
dependencies { compile 'com.google.android.gms:play-services:8.3.0' } 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
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' } 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 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.
defaultConfig { // Enabling multidex . multiDexEnabled true } dexOptions { incremental true javaMaxHeapSize "2048M" jumboMode = true } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:multidex:1.0.1' } 123456789101112131415 defaultConfig { // Enabling multidex . 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
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' } 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
@Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); //include this method MultiDex.install(this); } 123456 @Overrideprotected void attachBaseContext(Context base) { super.attachBaseContext(base); //include this method MultiDex.install(this);}
also add in OnCreate method too
@Override public void onCreate() { //include this method MultiDex.install(this); super.onCreate(); } 12345 @Overridepublic void onCreate() { //include this method MultiDex.install(this); super.onCreate(); }
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Name
Email
Subject
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.