Android Studio - Gradle incremental build

11,176

Solution 1

Finally found a solution. It was in the official docs all along, I just needed a deeper understanding of the build process to understand what was being said.

Incremental builds and multidex are indeed incompatible options. However, for sdk versions 21+ 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

Solution 2

I tried this option today (13 Nov 2017) and got the following build warning:

Warning:The android.dexOptions.incremental property is deprecated and it has no effect on the build process.

I then googled for the warning message and the answer confirmed that since a newer Gradle release, the entry is deprecated. See android.dexOptions.incremental property is deprecated

Solution 3

I do not have a direct answer how to solve the problem with Gradle, but I have a suggestion that might help you increase the speed of your builds.

Recently I run into the same problem: our build took nearly 4 minutes. I tried different build options but didn't come to noticeable profit.

After some research, I run into Jrebel for Android. It is something like "Instant run" on steroids. It supports many types of changes (UI, methods, fields, etc) and updates application in real time without recreating activity (therefore, saving state). Usually, it takes ten-thirty seconds to apply any kind of change.

The tool is not free, but they provide different pricing options and trial account, so you can try it. It works as usual plugin for Android Studio or Eclipse and installation is very easy.

Update

Now they have even free version: link to post

Share:
11,176
Fabio Picchi
Author by

Fabio Picchi

Updated on July 24, 2022

Comments

  • Fabio Picchi
    Fabio Picchi almost 2 years

    In the last few days I have been trying to improve the build time for our project with no luck. I don't mind having to wait 1m40s for a clean build, but if I insert one line in a single java file, I get the same build time as in a clean build. I must be doing something wrong but I simply can't find any documentation or stack overflow question that points me in the right direction. I managed to gather a bunch of information that I will centralize here in the hope that someone with a better understanding of the topic explain me why I get these abysmal build times.

    Here it goes:

    • I understand that this option in my build.gradle file is what I seek.

      android {
          dexOptions {
              incremental true
          }
      ...
      

      Glorious incremental build. However, this doesn't work for me apparently because my project uses the multidex feature for retrocompatibility with android versions before Lollipop.

    • Proguard to the rescue! With Proguard I am able to minify my executable and remove all the unused methods. I got a couple of errors with proguard minify but was able to set it properly and get it working. Great! Dex generation takes about 20s for every build. Unfortunately, nothing is for free, and the proguard gradle task takes about 2m50s to run. Even worse than my initial case.

    Is there a solution to this problem?

    • nhaarman
      nhaarman over 8 years
      Does enabling offline work in Global Gradle settings help?
    • Fabio Picchi
      Fabio Picchi over 8 years
      Unfortunately, no. The task that is really time consuming in my build process is the dex generation. Fetching the dependencies is pretty fast actually.
  • Francis Toth
    Francis Toth over 8 years
    Have you considered to use BUCK ? google.com/search?q=buck+facebook&ie=utf-8&oe=utf-8
  • Fabio Picchi
    Fabio Picchi over 8 years
    I will look into it, thanks for the suggestion! I am not sure if I can use it at work but I will certainly try it at my personal project.