Android Studio Gradle Issue: OutOfMemoryError: PermGen space

AndroidGradleAndroid Studio

Android Problem Overview


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

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

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.

Solution 3 - Android

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

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

Solution 4 - Android

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.

Solution 5 - Android

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

Solution 6 - Android

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

Solution 7 - Android

Try adding this to your gradle.properties:

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

Solution 8 - Android

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]

Solution 9 - Android

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

Solution 10 - Android

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

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZaBlancView Question on Stackoverflow
Solution 1 - AndroidKarim VarelaView Answer on Stackoverflow
Solution 2 - AndroidsorenhkView Answer on Stackoverflow
Solution 3 - AndroidDDSView Answer on Stackoverflow
Solution 4 - AndroidCraig RussellView Answer on Stackoverflow
Solution 5 - Androidr02View Answer on Stackoverflow
Solution 6 - AndroidPritam BanerjeeView Answer on Stackoverflow
Solution 7 - AndroidAlécio CarvalhoView Answer on Stackoverflow
Solution 8 - AndroidMaxView Answer on Stackoverflow
Solution 9 - AndroidBryan BryceView Answer on Stackoverflow
Solution 10 - AndroidjaneshsView Answer on Stackoverflow