Android Studio Gradle OutofMemory Error

2019-02-25 22:36发布

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.

3条回答
你好瞎i
2楼-- · 2019-02-25 22:59

Try the following:

Ctrl + Alt + S -> Compiler -> Gradle

InVM Options field write:

-Xmx2048m -XX:MaxPermSize=512m

查看更多
Summer. ? 凉城
3楼-- · 2019-02-25 23:04

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
查看更多
Luminary・发光体
4楼-- · 2019-02-25 23:10

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.

查看更多
登录 后发表回答