Getting out of memory issue after updating buildToolsVersion '23.0.1' in Android studio

爷,独闯天下 提交于 2019-11-28 04:27:05
mhdjazmati

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

dexOptions {
    javaMaxHeapSize "4g"
}

Android Studio Google JAR file causing GC overhead limit exceeded error

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"
    }

    ......
}

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.

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

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.

dexOptions {
        javaMaxHeapSize "4g"
    }

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

Muhibbullah Muhi

use this in your app level build.gradle:

android {
    dexOptions {
        javaMaxHeapSize "4g"
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!