ZaBlanc
ZaBlanc

Reputation: 4718

Android Studio Gradle Issue: OutOfMemoryError: PermGen space

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...

Upvotes: 67

Views: 44080

Answers (10)

janeshs
janeshs

Reputation: 813

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

test {
    jvmArgs "-XX:MaxPermSize=1024m"
}

Upvotes: 0

Pritam Banerjee
Pritam Banerjee

Reputation: 18958

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

Upvotes: 2

Craig Russell
Craig Russell

Reputation: 3584

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.

Upvotes: 12

Bryan Bryce
Bryan Bryce

Reputation: 1379

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

Upvotes: 0

Max
Max

Reputation: 1

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]

Upvotes: 0

Alécio Carvalho
Alécio Carvalho

Reputation: 13657

Try adding this to your gradle.properties:

 org.gradle.jvmargs=-XX:MaxPermSize=512m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=utf-8

Upvotes: 1

Karim Varela
Karim Varela

Reputation: 7652

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

Upvotes: 115

r02
r02

Reputation: 301

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).

Upvotes: 4

sorenhk
sorenhk

Reputation: 1607

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.

Upvotes: 43

DDS
DDS

Reputation: 590

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

/Applications/Android Studio.app/bin/idea.vmoptions

Upvotes: 14

Related Questions