Android Studio - Gradle incremental build

In the last few days, I tried to improve the build time for our project without any luck. I don't mind waiting for 1m40s for a clean build, but if I insert one line into a single java file, I get the same build time as in a clean build. I must be doing something wrong, but I just can't find the documentation overflow question or the stack that points me in the right direction. I managed to gather a ton of information, which I will centralize here, in the hope that someone who better understands this topic will explain to me why I get these terrible build times.

Here he is:

  • I understand that this parameter in my build.gradle file is what I am looking for.

    android { dexOptions { incremental true } ... 

    Nice incremental build. However, this does not work for me, apparently because my project uses the multidex function to retro-resist with Android versions prior to Lollipop.

  • Prologue to the rescue! With Proguard, I can minimize my executable and remove all unused methods. I have a couple of errors with proguard minify, but I was able to install it correctly and make it work. Large! Dex generation takes about 20 seconds for each build. Unfortunately, nothing is free, and the proguard gradle task takes about 2m50s to run. Even worse than my original case.

Is there a solution to this problem?

+6
source share
3 answers

Finally found a solution. This was in official docs all the time, I just needed a deeper understanding of the assembly process in order to understand what was being said.

Incremental builds and multidex are truly incompatible options. However, for sdk 21+ versions, incremental builds are possible for multidex apks by rebuilding only the affected dex files. Further information can be found here:

http://developer.android.com/tools/building/multidex.html

+10
source

I have no direct answer on how to solve the problem using Gradle, but I have a suggestion that can help you increase the speed of your collections.

I recently ran into the same problem: our assembly took about 4 minutes. I tried different build options, but did not get any noticeable profit.

After some research, I came across Jrebel for Android . This is something like "Instant run" on steroids. It supports many types of changes (user interface, methods, fields, etc.) and updates the application in real time without repeated activity (therefore, saving state). It usually takes ten thirty seconds to apply any changes.

The tool is not free, but they provide different pricing options and a trial account, so you can try it. It works like a regular plugin for Android Studio or Eclipse, and the installation is very simple.

Update

Now they even have a free version: link for publication

+3
source

I tried this option today (November 13, 2017) and received the following build warning:

A warning. The android.dexOptions.incremental property is deprecated and does not affect the build process.

Then I ran a warning message and the answer confirmed that the record is out of date with the new version of Gradle. See android.dexOptions.incremental property is deprecated

0
source

All Articles