Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit DEX memory usage

I am trying to set the maximum memory that DEX task can use in a gradle-based Android project, but can't find any option to do that.

My motivation to do this is because as dex sometimes takes so much memory that my computer starts swapping and becomes completely unresponsive for some minutes (so I would rather see the task fail and then free some more resources and retry)

In my gradle.properties I have org.gradle.jvmargs="-Xmx300m" which limits the memory used by Gradle itself, but when Gradle starts dx it always uses -Xmx1024.

So how can I make Gradle limit the memory used by dx?

like image 944
Salem Avatar asked Oct 15 '14 08:10

Salem


1 Answers

In your build.gradle script, set the dexOptions.javaMaxHeapSize configuration to whatever value you need:

android {
//snip
//add this into your existing 'android' block
    dexOptions {
        javaMaxHeapSize "4g"
    }
//snip
}

Source

like image 172
Alex Lipov Avatar answered Nov 03 '22 01:11

Alex Lipov