Android Studio Build gradle OutOfMemoryError

One of the methods below should work for you:


Open file from your project tree
add this line at the memory allocation line

org.gradle.jvmargs=-XX:MaxHeapSize=256m -Xmx256m


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


org.gradle.jvmargs=-XX:MaxHeapSize=1024m -Xmx1024m

Depending on the Memory of your computer. Then

Invalidate Caches/Restart project from the File > Invalidate Caches/Restart

To clean up your gradle cache and implement your new heap size memory changes


Step 1 : Start Android studio and close any open project (File > Close Project).

Step 2 : On Welcome window, Go to Configure > Settings.

Step 3 : Go to Build, Execution, Deployment > Compiler

Step 4 : Change Build process heap size (Mbytes) to 512 and Additional build process to VM Options to -Xmx512m. Or any memory allocation in correspondent to your PC

Step 5 : Revalidate/Restart Android Studio.

enter image description here


Go to your Android Studio Folder Where it is installed. There is File stduio.exe and studio64.exe with file type of VMOPTIONS, open it in notepad you will see Something like this:



Then change two values to suite you memory as below


My current jvmargs were set to


I had to update gradle to 4.10.1 to get rid of this error. Modify your gradle/wrapper/ file as below


Leave a Comment