Increase heap size available to dex operation in gradle

12,820 views
Skip to first unread message

Justin Breitfeller

unread,
Oct 17, 2013, 6:10:29 PM10/17/13
to adt...@googlegroups.com
Is there a way to increase the maximum heap size for the dex operation that is invoked when compiling with gradle?

Thanks,
Justin

Jake Wharton

unread,
Oct 17, 2013, 7:22:25 PM10/17/13
to adt...@googlegroups.com
Export a GRADLE_OPTS with the normal java flags for increasing heap, etc. You can also customize the gradle wrapper scripts to tweak values.

--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Justin Breitfeller

unread,
Oct 17, 2013, 8:37:03 PM10/17/13
to adt...@googlegroups.com
This is exactly what I have in my gradlew.bat file:

set GRADLE_OPTS=-XX:MaxPermSize=2048m -Xmx4096m -XX:MaxHeapSize=4096m %GRADLE_OPTS%
set JAVA_OPTS=-XX:MaxPermSize=2048m -Xmx4096m -XX:MaxHeapSize=4096m %JAVA_OPTS%
set DEFAULT_JVM_OPTS=-Xmx4096m -XX:MaxPermSize=2048m

Is there something I am missing? I really hope that my build isn't requiring more than 4 gigs of heap space.


The stack trace I get is as follows:


UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: Java heap space
        at java.util.BitSet.initWords(BitSet.java:144)
        at java.util.BitSet.<init>(BitSet.java:139)
        at com.android.dx.ssa.SsaMethod.bitSetFromLabelList(SsaMethod.java:138)
        at com.android.dx.ssa.SsaBasicBlock.newFromRop(SsaBasicBlock.java:158)
        at com.android.dx.ssa.SsaMethod.convertRopToSsaBlocks(SsaMethod.java:174)
        at com.android.dx.ssa.SsaMethod.newFromRopMethod(SsaMethod.java:104)
        at com.android.dx.ssa.SsaConverter.convertToSsaMethod(SsaConverter.java:45)
        at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:99)
        at com.android.dx.ssa.Optimizer.optimize(Optimizer.java:73)
        at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:273)
        at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:134)
        at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:87)
        at com.android.dx.command.dexer.Main.processClass(Main.java:487)
        at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
        at com.android.dx.command.dexer.Main.access$400(Main.java:67)
        at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.ja
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:1
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
        at com.android.dx.command.dexer.Main.processOne(Main.java:422)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
        at com.android.dx.command.dexer.Main.run(Main.java:209)
        at com.android.dx.command.dexer.Main.main(Main.java:174)
        at com.android.dx.command.Main.main(Main.java:91)

Avram Lyon

unread,
Oct 18, 2013, 1:30:54 AM10/18/13
to adt...@googlegroups.com

There is an undocumented field on dexOptions:

android {
    <snip>

    dexOptions {
        javaMaxHeapSize "4g"

    }
}


This made our migration to Gradle possible. And a whole lot less finicky.

- Avram


Avram Lyon
Android wrangler | Scopely, Inc.

Refer The Smartest Person You Know And Pocket $5,000! 
Learn more: scopely.com/referrals



On Thu, Oct 17, 2013 at 3:10 PM, Justin Breitfeller <mrs...@gmail.com> wrote:

--

Avram Lyon

unread,
Oct 18, 2013, 1:35:47 AM10/18/13
to adt...@googlegroups.com
Technically, the source for this option is here: https://android.googlesource.com/platform/tools/build/+/master/gradle/src/main/groovy/com/android/build/gradle/internal/dsl/DexOptionsImpl.groovy

The com.android.build.gradle.internal.dsl package is likely the only complete definition we currently have of the full DSL, so just read through it for more tidbits. Like that we can’t specify heap in units larger than terabytes.


Avram Lyon
Android wrangler | Scopely, Inc.

Refer The Smartest Person You Know And Pocket $5,000! 
Learn more: scopely.com/referrals



Justin Breitfeller

unread,
Oct 18, 2013, 9:58:55 AM10/18/13
to adt...@googlegroups.com
Awesome. That fixed my problem. Guess I will be digging through this to see if there is a way to turn off manifest merging.

Justin Breitfeller

unread,
Oct 18, 2013, 5:58:52 PM10/18/13
to adt...@googlegroups.com
Do you know of a way that I can put this in the build.gradle file in my root directory so that it is applied to all of my projects?

jiqing yao

unread,
Oct 19, 2013, 7:39:53 AM10/19/13
to adt...@googlegroups.com
I was able to disable manifest merging by using this 

// disable merge manifest
android.applicationVariants.all { variant ->
    variant.processResources.manifestFile = file('AndroidManifest.xml')
    variant.processManifest.enabled=false
}


On Friday, October 18, 2013 9:58:55 AM UTC-4, Justin Breitfeller wrote:
Reply all
Reply to author
Forward
0 new messages