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

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


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=trueorg.gradle.parallel=trueorg.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.


EDIT: Android Studio now has RAM configuration in its settings. Go to "help"->"change memory settings".


Find the Memory Settings

  1. Cmd + Shift + A on Mac (Ctrl + Shift + A on Windows) or click on Help
  2. Type "Memory Settings"

under Preferences/ Settings and increase the IDE Heap Size and/ or the Daemon Heap Size to your satisfactionenter image description here