5

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?

Salem
  • 12,808
  • 4
  • 34
  • 54

1 Answers1

14

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

Alex Lipov
  • 13,503
  • 5
  • 64
  • 87