Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you adjust jvm args for dex memory in gradle?

I have an Android project which is currently running out of heap space during the dex step:

 :app:dexXXXXX Exception in thread "pool-1-thread-4"  java.lang.OutOfMemoryError: Java heap space

I would like to bump up the jvm min/max settings in gradle like we used to do with the Maven plugin:

      <groupId>com.jayway.maven.plugins.android.generation2</groupId>
      <artifactId>android-maven-plugin</artifactId>
      <version>3.6.0</version>
      <extensions>true</extensions>
      <configuration>
        <sdk>
          <platform>${android.platform}</platform>
        </sdk>
        <undeployBeforeDeploy>true</undeployBeforeDeploy>
        <dex>
          <jvmArguments>
              <jvmArgument>-Xms1024m</jvmArgument>
              <jvmArgument>-Xmx2048m</jvmArgument>
          </jvmArguments>
        </dex>

But in the docs for the android plugin in gradle I only see these options:

   android {
    dexOptions {
        incremental false
        preDexLibraries = false
        jumboMode = false
    }
   }

Is there a way to do it? There is a gradle.properties file but that just seems to have jvmargs for gradle itself.

like image 522
Richard Guion Avatar asked May 15 '14 20:05

Richard Guion


People also ask

How much RAM do you want to allocate to gradle?

512MB is more than enough for most builds. Larger builds with hundreds of subprojects, lots of configuration, and source code may require, or perform better, with more memory.


1 Answers

There is an undocumented dexOptions flag.

dexOptions { javaMaxHeapSize "2g" }

I found the flag from a google groups post. https://groups.google.com/forum/#!topic/adt-dev/P_TLBTyFWVY

like image 157
Reid Baker Avatar answered Oct 03 '22 11:10

Reid Baker