32

I am getting gradle build error while running the app. I am using windows 10 with 8GB RAM, Android studio version 4.0.1

Out of memory: 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

Even after following the same steps I am not able to run the app. Could anyone help with a permanent solution for this error???

Here is my gradle.properties file:

android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1024m
3
  • Can you tell me which os you using ? (Windows/Mac...) how many GB of RAM you have ? And share your project gradle.properties please Commented Jul 25, 2020 at 12:51
  • I have edited my question Commented Jul 25, 2020 at 13:00
  • Take a look at this stackoverflow.com/questions/39547100/… Commented Jul 25, 2020 at 13:08

4 Answers 4

31
  1. Give more RAM for gradle org.gradle.jvmargs=-Xmx4g
  2. If you face the same problem after can run for a few times, open Task Manager, End task any Open JDK Platform binary or Java(TM) Se Binary to release RAM, then you can run project again.

If your computer have less than 8GB RAM, set like this in your gradle.properties org.gradle.jvmargs=-Xmx2048M

Sign up to request clarification or add additional context in comments.

Comments

9

I faced the same issue in my "react": "17.0.2","react-native": "0.66.1" project
Goto project/android/gradlew.properties
& uncomment this line
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

and only change the code before colan(:)
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX to
org.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=512m -XX

then save and run your build

1 Comment

Remove -XX:+HeapDumpOnOutOfMemoryError , because it creates dump files in your SSD
7

I'm working on a big android project with multiple modules and flavors and had the same problem.

I tried everything from tweaking memory to cleaning project, restarting while invalidating cache, deleting sources and recloning from repo.

I ended up deleting the ".gradle" folder in my user folder and recloning my project.. and it worked. Lost a lot of time on this though.

Comments

-3

Adding android:largeHeap="true" to the AndroidManifest.xml may solve your problem, if you haven't already added. But note that the main issue is your app is consuming too much memory. Consider tracking your app at runtime to find the unusual memory consuming process/objects.

<manifest 
     ...
     <application 
         android:largeHeap="true"
         ...

     </application>
</manifest>

5 Comments

I have already added, it worked once but when I tried to run again then same error
There can be many possibilities leading to OutOfMemoryException. ListViews, too many living Fragments, loading high quality images etc. So try to figure out the memory killer objects in your code.
This for app when u can build, the error message appear when he building the project
Yes I am not able to run my app then how would I figure out anything?
android:largeHeap does not fix memory issues during gradle build. That flag only affects your app in production. The OP has issues when app is being built / compiled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.