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

前端 未结 23 2712
甜味超标
甜味超标 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: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();
    }
    

提交回复
热议问题