7

I am new on Android development and my Gradle build process tooks long time. Its annoying for me to wait for gradle build. Any Help is appriciated. Thanks in advance

3 Answers3

9

There are some solutions I have mentioned:

Technique #1

  1. Open up gradle.properties file

  2. add the following line

org.gradle.daemon=true

Technique #2

  1. Open up gradle.properties file

  2. add the following line

    org.gradle.parallel=true

Technique #3

  1. Open up gradle.properties file

  2. add the following line

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

Technique #4
There are many other techniques for optimizing the speed of gradle build. If you are still having the problem I prefer you to use gradle from command line. For more details, you can see a discussion on G+ with the developers about it.

Ngima Sherpa
  • 1,397
  • 1
  • 13
  • 34
6

I would suggest running all 3 of the techniques along with some android gradle plugin dexOptions too:

I have the following my gradle.properties file:

org.gradle.daemon=true
org.gradle.jvmargs=-Djava.awt.headless=true -Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true

I also have dexOptions in the app/build.gradle file too:

dexOptions {
  incremental true
  javaMaxHeapSize "4096M"
  jumboMode true
  maxProcessCount 8
  preDexLibraries false
  threadCount 8
}

You can tune those values for you system. Here is more information about those options:

dexInProcess - Whether to run the dx compiler as a separate process or inside the Gradle daemon JVM.

javaMaxHeapSize - Specifies the -Xmx value when calling dx. Example value is "2048m".

jumboMode - Enable jumbo mode in dx (--force-jumbo).

maxProcessCount - The maximum number of concurrent processes that can be used to dex. Defaults to 4.

preDexLibraries - Whether to pre-dex libraries. This can improve incremental builds, but clean builds may be slower.

threadCount - Number of threads to use when running dx. Defaults to 4.

Ray Hunter
  • 15,137
  • 5
  • 53
  • 51
0

I just accidentally found how to build 2 times faster. May be it will be fix in the future, but now it works like clockwork. All you need to is hide your studio (cmd + H or cmd + R for mac, win + D for Windows). I tested it with more then 100 builds for now (Android Studio 2.3), there were no exceptions.

Artur Dumchev
  • 1,252
  • 14
  • 17