Java.lang.OutOfMemoryError: PermGen space in Android Gradle Build

I didn’t make changes in my circle.yml, it just stopped working
My cycle.yml -

Building 57%8% > :app:mergeProdReleaseResources:app:mergeProdReleaseResources
Building 58%9% > :app:processProdReleaseManifest:app:processProdReleaseManifest
Building 59%60% > :app:processProdReleaseResources:app:processProdReleaseResources
Building 60%1% > :app:generateProdReleaseSources:app:generateProdReleaseSources
Building 61% > :app:incrementalProdReleaseJavaCompilationSafeguard:app:incrementalProdReleaseJavaCompilationSafeguard
Building 61%2% > :app:compileProdReleaseJavaWithJavac:app:compileProdReleaseJavaWithJavac
Building 62%FAILED
Building 62%
Building 62%3%java.lang.OutOfMemoryError: PermGen space
Building 63%java.lang.OutOfMemoryError: PermGen space
Building 63%java.lang.OutOfMemoryError: PermGen space
Building 63%java.lang.OutOfMemoryError: PermGen space
Building 63%The message received from the daemon indicates that the daemon has disappeared.
Building 63%Build request sent: Build{id=1bb651ca-6962-4bfe-a5de-8488357ab495.1, currentDir=/home/ubuntu/alua-android}
Building 63%Attempting to read last messages from the daemon log…
Building 63%
Building 63%Daemon pid: 13501

Hey there! I just replied to you in Zendesk, but if anyone else has this issue this is due to the fact that some android projects will OOM if you are using modern tooling. This is a known issue and the only thing we can really do right now is bump up the RAM on the builder. Please ping us in-app if you need us to do this.

@levlaz Actually… there’s another way to get around this. If you bump the minSdkVersion to 21+ then various memory intensive Gradle tasks will not be runned. Granted, bumping minSdkVersion is a non-starter for most apps. But what we do is we added a flavor we use to build tests. This flavor is minSdkVersion 21 while the other app flavors are minSdkVersion 16. Then we just build the app with that flavor in our circle.yml. Also remember to add the disable Pre Dex option…

$ ./gradlew :mobile:testTestingFlavorDebugUnitTest -PdisablePreDex


I suggest here changing the GRADLE_OPTS variable to:
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:MaxPermSize=1024m -Xms512m -XX:+HeapDumpOnOutOfMemoryError"'. This worked for me along with increasing the RAM on build machines


I am experiencing the same error. I already did all the suggested workarounds, but keep getting OOM exception.
How can I ping you @levlaz in-app as you say in order to boost the RAM?


I was still experiencing issues after following the suggestions above. I found adding the following to build.gradle:

gradle.projectsEvaluated {
    tasks.withType(Test) { task ->
        if (project.hasProperty('verboseTests')) {
            task.beforeTest { descriptor ->
                println "Executing test ${} [${descriptor.className}]"

And this to circle.yml:

    - ./gradlew testDebugUnitTest '-PverboseTests':
        timeout: 1800

Fixed my problem. I wonder if outputting test names before each test is enough of a pause in the tests running that garbage collection can take place.

Are you sure it’s not -PpreDexEnable?