19

I'm new in Android. I import Github project in Android studio, but i see this problem `Error:java.lang.OutOfMemoryError: Java heap space

Error:java.lang.OutOfMemoryError: Java heap space . Please assign more memory to Gradle in the project's gradle.properties file. For example, the following line, in the gradle.properties file, sets the maximum Java heap size to 1,024 MB: org.gradle.jvmargs=-Xmx1024m Read Gradle's configuration guide
Read about Java's heap size

I can't fix this problem with this . how should i do to fix that?

MrNadimi
  • 1,114
  • 3
  • 15
  • 28
  • Maybe this can help: [link](http://stackoverflow.com/questions/32133013/java-lang-outofmemoryerror-gc-overhead-limit-exceeded-on-android-1-4) – Rouhollah Mazarei Sep 17 '16 at 13:01

2 Answers2

35

One of the methods below should work for you:

METHOD 1 :

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

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

or

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

or

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

METHOD 2 :

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

METHOD 3 :

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:

-Xms512m
-Xmx1280m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=225m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-ea
-Djna.nosys=true
-Djna.boot.library.path=

-Djna.debug_load=true
-Djna.debug_load.jna=true
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-Didea.paths.selector=AndroidStudio1.3
-Didea.platform.prefix=AndroidStudio

Then change two values to suite you memory as below

-Xms512m
-Xmx1280m
Thecarisma
  • 1,127
  • 13
  • 17
  • i added them(part 1, part 2 , part 3) . i do these steps but i have Error yet – MrNadimi Sep 17 '16 at 20:41
  • I have updated my answer with two other methods. I am very sure the methods will work for you else i will advise you to _update your IDE_ and/or look into your **Android SDK** – Thecarisma Sep 17 '16 at 22:03
  • thank you for your help but my problem have not solve yet . when i changed -Xms512m . . i can not open my Android Studio . – MrNadimi Sep 22 '16 at 12:40
  • updating your **android studio IDE** and **The Android SDK** – Thecarisma Sep 22 '16 at 12:50
  • both of them updated .but there is another problem .. when i opening Android Studio ! after 1 sec it closed auto – MrNadimi Sep 22 '16 at 18:47
3

My current jvmargs were set to

org.gradle.jvmargs=-Xmx4096m

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

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
tomrozb
  • 23,522
  • 30
  • 89
  • 110
  • 2
    still facing the same issue my currant is this `distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip` – Arbaz.in Apr 16 '20 at 14:02