How to speed up Gradle build process in Android Studio

I am new to Android development, and my Gradle build process took a long time. Its annoying for me to wait for the Gradle build. Any help is assigned. thanks in advance

+7
android android-studio android-gradle
source share
3 answers

There are some solutions that I mentioned:

Technique number 1

  • Open gradle.properties file

  • add the following line

org.gradle.daemon = true

Technique number 2

  • Open gradle.properties file

  • add next line

    org.gradle.parallel = true

Technique number 3

  • Open gradle.properties file

  • add next line

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

Technique number 4
There are many other methods to optimize gradle build speed. If you still have a problem, I prefer to use gradle from the command line. For more details, you can see a discussion in G + with the developers about this.

+6
source share

I would suggest running all three methods along with some dexOptions of the android gradle plugin:

I have the following 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 :

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

You can configure these values ​​for your system. Here is more detailed information about these options:

dexInProcess - run the dx compiler as a separate process or inside the gradle JVM daemon.

javaMaxHeapSize . Specifies the value -Xmx when dx is called. The approximate value is "2048 m".

jumboMode Turn jumbo mode on dx (--force-jumbo).

maxProcessCount . The maximum number of concurrent processes that can be used for dex. The default is 4.

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

threadCount . The number of threads to use when starting dx. The default is 4.

+6
source share

I just accidentally found how to build 2 times faster. This may be fixed in the future, but now it works like a clock. All you need to do is hide your studio (cmd + H or cmd + R for mac, win + D for Windows). I tested it with more than 100 builds at the moment (Android Studio 2.3), there were no exceptions.

0
source share

All Articles