2

Ive been trying to import my android project into a new computer with Android Studio 0.5.2 after each gradle build i get:

Out of memory: Java heap space. Configure Gradle memory settings using '-Xmx' JVM option (e.g. '-Xmx2048m'.)
    Please fix the project's Gradle settings.
    Gradle settings

The project isnt very big,only thing im using is google play services and i dont believe it requires alot of memory.For this has a head scratcher and i dont know what to do.

The Kid
  • 21
  • 1
  • 2

3 Answers3

8

Try the following:

Ctrl + Alt + S -> Compiler -> Gradle

InVM Options field write:

-Xmx2048m -XX:MaxPermSize=512m

Dima
  • 1,490
  • 16
  • 25
  • 1
    Almost for me. I had to do this: Build, Exectuion, Deployment -> Compiler -> Command-line Options: -Xmx3072m -XX:MaxPermSize=512m – Keith Holliday Jun 08 '16 at 21:45
2

Note that in today's Android Studio version you can do it directly in the GUI, no need for command-line parameters:

screenshot of error message with default values

This can also be set by editing a settings file: For Windows, the file located at c:\Users\USERNAME\.AndroidStudioXXX\config - in this folder, look for a file with extension of .vmoptions. In that file, you can set the following lines, for example:

-Xms256m
-Xmx4096m
-XX:ReservedCodeCacheSize=240m

Note that these changes should be done when Android Studio is closed. After changing the values and saving the file, reopen Android Studio and it should work faster than before.

Yoav Feuerstein
  • 1,925
  • 2
  • 22
  • 53
  • @Makalele It used to show by itself, after Android Studio (or the build process) was stuck for some time. You can also change it in the IDE's settings, as explain in the other comment in this thread. – Yoav Feuerstein Mar 19 '18 at 11:01
  • It does not in my case. However I have this error in gradle compiler, not in IDE itself. I've just searched in like 100+ answers and still cannot run the project. Out of memory all the time. Tried clearing caches, cleaning project. – Makalele Mar 19 '18 at 11:03
  • @Makalele what exact command(s) do you use in order to trigger the build process? – Yoav Feuerstein Mar 20 '18 at 09:57
  • I just used "play" button in Android studio. Later I've added --stacktrace to see what the error is. In the end, I've resolved this issue by getting older version of the project and copying changed code. Somehow, it worked and I no longer see memory issues. – Makalele Mar 20 '18 at 11:40
  • @Makalele please see my updated answer, with more information below the image. – Yoav Feuerstein Jul 09 '18 at 14:53
  • 1
    Thank you very much, man, you just saved my life! I got the error "maxjavastacktradeepth = -1 is outside allowed range" and I searched a lot of time and did not find a solution until I found your answers by accident, I love you man! – Mahmoud Metawee Feb 06 '19 at 05:12
0

You can also got to: Help > Edit Custom VM Options...

custom Android Studio VM options, see http://tools.android.com/tech-docs/configuration

-server
-Xms512m
-Xmx2048m
-XX:ReservedCodeCacheSize=720m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=100
-ea
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-XX:+HeapDumpOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow
-XX:MaxJavaStackTraceDepth=-1
Javatar
  • 2,518
  • 1
  • 31
  • 43