Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Build failed - Java.exe is finished with non-zero exit value 2

I have added recyclerview gradle build and then tried to run the app, and now I get this 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_79\bin\java.exe'' finished with non-zero exit value 2

Here is my gradle build file:

dependencies {
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
compile 'com.parse.bolts:bolts-android:1.2.0'
compile 'com.android.support:design:22.2.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.facebook.fresco:fresco:0.5.2+'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile fileTree(dir: 'libs', include: 'commons-io-*.jar')
compile fileTree(dir: 'libs', include: 'ParseFacebookUtilsV4-*.jar')
}

How to fix this?

like image 938
Zookey Avatar asked Jan 09 '23 00:01

Zookey


2 Answers

It looks like you have reached the dex limit and you have over 65k methods in your application.

If you want to keep all of your gradle dependencies as is, you should look into configuring multidex that way it will build your application using multiple dex files.

Another solution would be to try and remove any unnecessary dependencies from the google play services library. Chances are you don't need to include everything and you can choose to add only the imports you need.

For example:

com.google.android.gms:play-services-maps:7.5.0
com.google.android.gms:play-services-gcm:7.5.0

Rather than simply using:

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

You can reference the Google Play Services guide to determine which pieces of library you should add.

like image 82
Andrea Thacker Avatar answered Jan 31 '23 20:01

Andrea Thacker


Android Studio suggests,

Avoid using + in version numbers can lead to unpredictable and unrepeatable builds.

+ in dependencies lets you pick up automatically the latest available version rather than a specific one, however this is not recommended.

You may have tested with a slightly different version than what build server used.

After Removing Plus Sign and Adding a Specific Version problem was solved.

like image 42
Palak Avatar answered Jan 31 '23 20:01

Palak