Out of memory issue after updating buildToolsVersion '23.0.1' in Android studio

AndroidAndroid Studiobuild.gradleAndroid BuildBuild Tools

Android Problem Overview


I am getting out of memory issue very often after updating buildToolsVersion '22.0.1' to buildToolsVersion '23.0.1' I am really confused and don't know how to solve this issue, since this error showing only with buildTools version 23.0.1. Whereas it is working fine when I change it to 22.0.1. Please help me. I am posting the error which I am getting as follows,

Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_25\bin\java.exe'' finished with non-zero exit value 1

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'

    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        // Enabling multidex support.
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
   
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.android.support:design:23.0.0'
    compile 'com.android.support:cardview-v7:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.android.support:palette-v7:23.0.1'
    compile 'com.google.android.gms:play-services:7.5.0'
}

Thanks in advance.

Android Solutions


Solution 1 - Android

Add this to your android closure in your build.gradle file:

dexOptions {
    javaMaxHeapSize "4g"
}

https://stackoverflow.com/questions/25013638/android-studio-google-jar-causing-gc-overhead-limit-exceeded-error

Solution 2 - Android

The accepted answer works but I was confused for a bit about where to put the dexOptions in my build.gradle. We actually put it under the android section.

Here is example snippet:

android {

    dexOptions {
        javaMaxHeapSize "4g"
    }
	
	......
}

Solution 3 - Android

Actually for me worked a more complex solution, which combine all from above, plus enabling multidex in the build.gradle file for the module.

A. Add this line in the defaultConfig section to enable multiDex

// Enabling multidex support.
multiDexEnabled true

B. Than set the dexOptions, like this:

dexOptions {
    incremental true
    javaMaxHeapSize "4G"
}

C. After changing to multidex and setting the heap to 4g, an overflow error may occur which lead me to uncomment and modify the jvmargs line from gradle.properties file of the project, like:

org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

The values may differ depending on your machine. You can also use double values.

Solution 4 - Android

In addition to above procedure, there is another option to set jvm arguments.

org.gradle.jvmargs="-Xms2g -Xmx4g" in gradle.properties .

The setting is for tweaking memory. Xms: Starting memory Xmx: Max memory

Solution 5 - Android

I solved this problem

  1. go to "System"
  2. Environmental Setting Adwanced
  3. Edit _JAVA_OPTIONS values from "-Xms1024m" to "-Xms2048m"
    (if not Exist _JAVA_OPTIONS than create it click on New Button)
  4. ok & save Restart

I think it will be helpfull for you also. if it usefull upvote this answer.

Solution 6 - Android

dexOptions {
        javaMaxHeapSize "4g"
    }

I was facing the same issue by adding this in build.gradle file (module level) solved my problem

Solution 7 - Android

use this in your app level build.gradle:

android {
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChandruView Question on Stackoverflow
Solution 1 - AndroidmhdjazmatiView Answer on Stackoverflow
Solution 2 - AndroidMaxView Answer on Stackoverflow
Solution 3 - AndroidCodrut TGView Answer on Stackoverflow
Solution 4 - AndroidAnnadaView Answer on Stackoverflow
Solution 5 - AndroidDineshView Answer on Stackoverflow
Solution 6 - AndroidMohsin BagwanView Answer on Stackoverflow
Solution 7 - AndroidMuhibbullah MuhiView Answer on Stackoverflow