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

前端 未结 23 2390
甜味超标
甜味超标 2020-11-22 02:54

I\'m getting this error executing my Android app (I cleaned it and then built it, but the error is still present)

  • Sync: OK
  • Make Project: OK
相关标签:
23条回答
  • 2020-11-22 03:13

    If You have already updated your SDK and You also using google-play-services then you need to take care of the dependency because there are some kind of conflics with :

    Follow the below : compile 'com.google.android.gms:play-services:+' Replace by compile 'com.google.android.gms:play-services:6.5.87'

    Note: Here '6.5.87' is the google-play-service version. I hope it will help..

    0 讨论(0)
  • 2020-11-22 03:15

    For me the problem was, i had put a 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'
    

    Hi people i again encountered this problem and this time it was because of changing build tools version and it really required me to enable multidex..so i added these my app's build.gradle file..

    defaultConfig {
        applicationId "com.am.android"
        minSdkVersion 13
        targetSdkVersion 23
        // Enabling multidex support.
        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 that extends Application class and include this method inside the class..

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
    

    also include in OnCreate method too

    @Override
    public void onCreate() {
        MultiDex.install(this);
        super.onCreate();
    }
    
    0 讨论(0)
  • 2020-11-22 03:15

    Mine got solved by enabling multiDex for debug builds.

    defaultConfig {
    multiDexEnabled true
    }
    
    0 讨论(0)
  • 2020-11-22 03:17

    You may be using a low quality cable/defected cable to connect your device to the PC, I replaced the cable and it worked for me.

    0 讨论(0)
  • 2020-11-22 03:18

    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
    }
    

    You can read more about multidex support and developing apps with more than 65K methods here.

    0 讨论(0)
  • 2020-11-22 03:18

    Updating my Java SDK to the latest version 1.7.0_79 and updating the SDK Location under Project Structure solved the problem for me.

    0 讨论(0)
提交回复
热议问题