8

In the official post detailing the features of the stable release of Android Studio 2.1, I came across this:

We are also speeding up build times by using in-process dex, which converts class files to dex files within the Gradle daemon process. This avoids the costly processing operation of creating separate dex processes. To use this feature, you will need to increase the amount of memory available to the Gradle daemon to at least 2GB (1 GB is the default).

Please, how can I increase the memory that's available to Gradle?

W.K.S
  • 9,787
  • 15
  • 75
  • 122
X09
  • 3,827
  • 10
  • 47
  • 92
  • 1
    Possible duplicate of [Android Studio Gradle Issue: OutOfMemoryError: PermGen space](http://stackoverflow.com/questions/17012619/android-studio-gradle-issue-outofmemoryerror-permgen-space) – ashwinbhy Apr 28 '16 at 11:45

3 Answers3

18

In Android Studio 2.1 open your gradle.properties file. Find the line

\# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

Uncomment the line. Gradle was faster after I did this.

Zong
  • 6,160
  • 5
  • 32
  • 46
13

In your app's build.gradle file, add the following:

android{
     //....
     dexOptions {
        javaMaxHeapSize "2g"
    }
}
W.K.S
  • 9,787
  • 15
  • 75
  • 122
3

I have not try this but it should works:

In graddle.build file:

apply plugin: 'java'

compileJava {
    //raise heap
    options.fork = 'true'
    options.forkOptions.with {
        memoryMaximumSize = '2048m'
    }
}

If it does not work in Windows try to add it to a new file gradle.properties next to gradle.build

References: http://www.gubatron.com/blog/2014/07/29/solved-gradle-how-to-increase-the-java-compilers-available-heap-memory/

I hope it helps you

chelmertz
  • 20,399
  • 5
  • 40
  • 46
Nestoraj
  • 722
  • 2
  • 6
  • 19
  • Link-only answers are discouraged on StackOverflow. Please include the relevant text and code from the link in your answer. – W.K.S Apr 28 '16 at 11:46
  • small nitpick but your quotes are stylized quotes and not standard ASCII quotes. makes for bad copy-paste. – fIwJlxSzApHEZIl Apr 18 '17 at 00:11