How to solve java.lang.OutOfMemoryError: GC overhead limit exceeded error in android studio

℡╲_俬逩灬. 提交于 2019-12-02 18:06:33
user3008777

I solved this issue by adding

dexOptions { 
          incremental true 
          javaMaxHeapSize "4g" 
} 

to the android closure in build.gradle file. Found this answer in

OutOfMemoryError: GC overhead limit exceeded

Add this to your "gradle.properties" file:

org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError

Also, read this article. You might be able to make the building a bit faster, by adding a combination of those:

org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true

EDIT: an updated answer based on my experience:

On Android Studio, choose Help -> Edit custom VM options , and then set the max memory the IDE is allowed to use. For example, if you want 5GB, use this:

-Xmx5g

Save the file, close all windows of the IDE (make sure it has no processes) and then restart the IDE.

Add this line in your build.gradle

dexOptions
         {
               incremental false
               javaMaxHeapSize "2048M" 
               preDexLibraries = false
         }

I had the same issue too - mine was for a different reason. I was working on backing up some files and accidentally dropped a big file in the resource folder. It was close to 40MB.

Once this file was removed, the error was gone.

mrljdx

I also have this problem my solution is : Just modify the gradle.properties in the root of your project :

org.gradle.jvmargs=-XX\:MaxHeapSize\=512m -Xmx512m

the default jvmargs is 256 when you compile a lot of channel apk then will cause this problem !

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