Faster Android Studio Builds with Dex In Process
An Android Tool Time Protip
Android Studio 2.1 enables a new feature: Dex In Process, that can dramatically increase the speed of full clean builds as well as improving Instant Run performance.
To take advantage of Dex In Process, you’ll need to modify your gradle.properties file and increase the amount of memory allocated to the Gradle Daemon VM by 1 Gb, to a minimum of 2 Gb, using the org.gradle.jvmargs property:
The default Gradle Daemon VM memory allocation is 1 gigabyte — which is insufficient to support dexInProcess, so to take advantage you’ll need to set it to at least 2 gigabytes.
Dex in process works by allowing multiple DEX processes to run within a single VM that’s also shared with Gradle, which is why you need to allocate the extra memory before it can be enabled — that memory will be shared between Gradle and multiple DEX processes.
If you’ve increased the javaMaxHeapSize in your module-level build.gradle file beyond the default of 1 gigabyte, you’ll need increase the memory assigned to the Gradle Daemon correspondingly.
When there’s enough memory assigned Dex in Process is enabled by default, improving overall build performance and removing the overhead of starting multiple parallel VM instances. The result is a significant improvement in all build times, including Instant Run, incremental, and full builds.
The best values values vary based on different hardware, so upgrade to Android Studio 2.1, and experiment with your jvmargs value to see what works best for you.