67

After several hours of fighting to get an older project imported from Eclipse to use Gradle and into Android Studio v0.1.3...what I've gotten to now is I can actually do the build on the command line, but when I do Build/Rebuild Project in Studio I get:

Gradle: 

FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':EpicMix'.
> Failed to notify project evaluation listener.
   > A problem occurred configuring project ':facebook'.
      > Failed to notify project evaluation listener.
         > java.lang.OutOfMemoryError: PermGen space

It's not a HUGE project, there's a few small sub-projects (including Facebook), so I don't think it really is memory. I just can't figure out what this is...

Ben
  • 51,770
  • 36
  • 127
  • 149
ZaBlanc
  • 4,679
  • 1
  • 35
  • 38

10 Answers10

115

For those of you running gradle from the command line, create a gradle.properties file, put it in the root of your project, and add the following:

org.gradle.jvmargs=-XX:MaxPermSize=512m
AZ_
  • 21,688
  • 25
  • 143
  • 191
Karim Varela
  • 7,562
  • 10
  • 53
  • 78
43

The size of the PermGen space can be increased within Android Studio under File > Settings > Compiler. Look for the setting named "Additional compiler process VM options". Just add the following parameter:

-XX:MaxPermSize=512M

The default value is 92M. Use G if you want to specify a value in gigabytes.

sorenhk
  • 1,597
  • 15
  • 9
14

If you are on Mac OS X it's possible to increase MaxPermSize inside file

/Applications/Android Studio.app/bin/idea.vmoptions
DDS
  • 590
  • 5
  • 9
  • 1
    Thanks, I've been looking for this for quite a while! – Brian Jul 18 '13 at 13:23
  • 1
    Note, Google recommends against doing this in the latest versions of the IDE. See my answer for what they recommend doing now: http://stackoverflow.com/a/30253323/1654145 – Craig Russell May 15 '15 at 06:56
12

The recommended way of setting JVM arguments, such as max PermGen size, is by following the advice given here - http://tools.android.com/tech-docs/configuration

Android Studio 2.0 and newer

As of Android Studio 2.0, there is an option to access the configuration file directly from the IDE.

Use the Help->Edit Custom VM Options menu. enter image description here

Taken from the configuration page, the full set of JVM arguments are as follows, alongs with their default values:

-Xms128m -Xmx750m -XX:MaxPermSize=350m -XX:ReservedCodeCacheSize=96m -XX:+UseCompressedOops

Legacy Instructions:

You should create your own studio.vmoptions file and put your JVM settings in here. The location of your file should be:

  • Mac OS ~/Library/Preferences/AndroidStudio/studio.vmoptions
  • Linux ~/.AndroidStudio/studio.vmoptions (or ~/.AndroidStudio/studio64.vmoptions)
  • Windows: %USERPROFILE%.AndroidStudio\studio.exe.vmoptions (or %USERPROFILE%.AndroidStudio\studio64.exe.vmoptions)

Note, you should no longer edit the files in the AndroidStudio app directory as these will be overwritten with each new installation/update to the IDE.

Craig Russell
  • 3,534
  • 3
  • 26
  • 27
4

Also, this worked for me - if you're in Linux, just set the environment variable GRADLE_OPTS to be "-XX:MaxPermSize=512m" (or whatever size you want).

Community
  • 1
  • 1
r02
  • 191
  • 2
  • 7
2

You can have a gradle.properties file and then add the following.

Create or edit the ~/.gradle/gradle.properties to include the following

org.gradle.daemon=false
GRADLE_OPTS="-Xmx2048m -Xms2048m -XX:MaxPermSize=1024m"
org.gradle.jvmargs=-XX:MaxPermSize=1024m
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
1

Try adding this to your gradle.properties:

 org.gradle.jvmargs=-XX:MaxPermSize=512m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=utf-8
Alécio Carvalho
  • 13,481
  • 5
  • 68
  • 74
0

At every build or clean several java processes are started causing Out of Memory errors.

Brute force solution:

Kill java.exe processes before any build or run. This will have side effects on any other active application working with java.

[Android Studio 1.4 - JRE 1.7.0_75-b13]

Max
  • 1
0

On a Mac go to ~/.gradle and delete both the caches and daemon folders. These get regenerated.

Bryan Bryce
  • 1,310
  • 1
  • 16
  • 29
0

In your Gradle build file add the following jvmArgs inside test {} block to increase the perm-gen space allocation:

test {
    jvmArgs "-XX:MaxPermSize=1024m"
}
janeshs
  • 793
  • 2
  • 12
  • 26