1

the event log say

5:11:08 PM Gradle sync started
5:11:35 PM Gradle sync failed: Process 'command '/usr/local/android-studio/jre/bin/java'' finished with non-zero exit value 2
           Consult IDE log for more details (Help | Show Log)

 delete .gradle file (fail)
 restart android studio/pc (fail)
 offline work (fail)
 use local gradle distro (fail)
 reinstall (fail)
 update android studio (fail)

for more information : this is the first time im using android studio.

edit : sorry for my formatting

Amsyar
  • 11
  • 3

5 Answers5

2

I did this in Android studio 2.3:

Download new version of gradle from http://services.gradle.org/distributions/ and extract it. Open your project go to file>settings choose build, execution, deployment select gradle choose 'use local gradle distribution' and set the path to the updated gradle. Import project again (make sure you're connected to the internet).

pacholik
  • 8,607
  • 9
  • 43
  • 55
sammy
  • 296
  • 2
  • 6
1

I have found the answer for me on askubuntu, but since I found this thread first, I'll post it here for others:

The problem is there in the error report:

/usr/local/android-studio/jre/bin/java

It tries to find a java runtime in its own folder, while you probably have java installed elsewhere. Simply go to File -> Other Settings -> Default Project Structure, and set the JDK folder to the root folder of your JDK. (e.g. C:\Program Files\jdk1.8.0_111)

I just wish it was more clear on what its problem was...

Community
  • 1
  • 1
XYZatesz
  • 11
  • 1
0

Try below codes in your app level build.gradle file

multiDexEnabled = true

dexOptions {
    preDexLibraries = false
    incremental true
    javaMaxHeapSize "4g"
}
nishith kumar
  • 981
  • 7
  • 20
0

This issue is quite possibly due to exceeding the 65K methods dex limit imposed by Android. This problem can be solved either by cleaning the project, and removing some unused libraries and methods from dependencies in build.gradle, OR by adding multidex support.

So, If you have to keep libraries and methods, then you can enable multi dex support by declaring it in the gradle config.

defaultConfig {        
// Enabling multidex support.
multiDexEnabled true
}

Also it is possible that two or more liabraries conflict (same library but different versions). Check your app build.gradle in dependencies block.

Swanand
  • 507
  • 6
  • 15
0

Here are possibility of mulitple reasone for Gradle Sync Failed.

1) You have same library or jar file included several places and some of them conflicting with each other.

2) Check if you have 2 classes with same name.

Solutions

1) Remove unnecessary complie library code in build.gradle

dependencies { compile 'com.google.android.gms:play-services:7.5.0' } which was causing over 65k methods, so removed it,gradle sync, cleaned project, and then ran again and then this error stopped. I needed just maps and gcm so i put these lines and synced project

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

2) Add below code to your build.gradle file.It may manage duplication of libraries

packagingOptions { exclude 'META-INF/NOTICE' exclude 'META-INF/notice.txt' exclude 'META-INF/NOTICE.txt' }

defaultConfig { ... ... multiDexEnabled true }

For Reference Java finished with non-zero exit value 2 - Android Gradle

Community
  • 1
  • 1
Patrick R
  • 6,621
  • 1
  • 24
  • 27