25
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:+'
}
Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226

7 Answers7

40

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
geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
nick252
  • 421
  • 3
  • 2
21

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
Cristian Holdunu
  • 1,880
  • 1
  • 18
  • 43
1

If anyone still facing the issue and there is no impact on increasing the IDE memory and gradle.properties than invalidate cache/restart is the last option for you. In my case it is working after invalidate cache/restart

Fazal Hussain
  • 1,129
  • 12
  • 28
  • same issue. have to invlidate/restart periodically. Any other solution? – Rinat Diushenov Jan 06 '21 at 10:53
  • No, I found this issue two times after invalidate cache/restart it was working fine. – Fazal Hussain Jan 08 '21 at 15:36
  • The problem is i have to restart/ invalidate after 3-4 builds, periodically or it just doesnt build, uses up 100 cpu and 8gb of ram. Not really a solution for me – Rinat Diushenov Jan 08 '21 at 17:12
  • 1
    invalidate cache/restart takes too long. My workaround for this is to kill jdk processes on task manager and make a clean build before rebuild. Hope it helps someone that face this issue. – caneru Oct 04 '21 at 10:41
0

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

sud007
  • 5,824
  • 4
  • 56
  • 63
nick252
  • 421
  • 3
  • 2
0

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

Imjaad
  • 588
  • 3
  • 12
0

Increasing the IDE memory help as long as there is available memory on device, and invalidate cache/restart takes too long. My workaround for this is to kill jdk processes on task manager and make a clean build before rebuild. Hope it helps someone that face this issue.

caneru
  • 391
  • 1
  • 2
  • 15
0

While most of the answers involve increasing of the heap memory and are correct. In case you just check-ed out the project (and can't even synchronise the gradle) the adjustment of gradle properties can also be done via the Android studio Preferences (Settings) by navigating to the following locations:

  • mac: Android Studio / Preferences / Appearance & Behavior / Memory Settings
  • windows: Android Studio / File / Settings / Appearance & Behavior / Memory Settings

Once you are in the correct settings i suggest you set the:

  • IDE max heap size: 2048 MB
  • Gradle daemon max heap size: 2048 MB
  • kOTLIN daemon max heap size: 2048 MB

Check the picture below: enter image description here

F.A. Botic
  • 71
  • 1
  • 2