Home » Android » Android Studio: GC overhead limit exceeded

Android Studio: GC overhead limit exceeded

Posted by: admin May 14, 2020 Leave a comment

Questions:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> java.lang.OutOfMemoryError: GC overhead limit exceeded

Tried:

dexOptions {
    javaMaxHeapSize "4g"
}

That seems to be the only solution available online.

But still it exceeds the limit on 2nd build, unless I kill the studio task and restart, which makes it work for the 1st time.

Definitely not many dependencies in the build.gradle

build.grade

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.xxxxx.android"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 8
        versionName "1.3"
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile 'com.squareup.okhttp:okhttp:2.3.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'de.greenrobot:eventbus:2.4.0'
    compile 'com.google.android.gms:play-services-location:+'
}
How to&Answers:

Increase the IDE memory (file studio.vmoptions)

http://tools.android.com/tech-docs/configuration

My settings:

-Xms256m
-Xmx3080m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=225m
-XX:+UseCompressedOops

Answer:

This is a problem of not enough java heap for gradle, not IDE

I increased Java Heap in gradle.properties

org.gradle.jvmargs=-Xms1024m -Xmx4096m

Answer:

It seems to be connected with this bug https://code.google.com/p/android/issues/detail?id=199619

Answer:

If somebody faces this issue in the future, and can’t increase the IDE memory, there is another option, you need to go to your android folder and there you will find a dump file that will be likely more than 400mb, delete that file and try again. Cheers