Android Build Speed Up. ver English

SeongUg Steve Jung
AndroidPub
Published in
3 min readNov 24, 2015

--

Chinese ver : ( http://blog.csdn.net/growth58/article/details/49589885 )

Eclipse to Android Studio…
Ant to Gradle…

After 2015 mid Google released Android Studio & Gradle Plugin 1.0. Android Development Environment was changed too much.

But many developer complained about spending too much time to build

Actually I was spent 2 times than before. I was too bad to me.

so I tried many thing to reduce building time. and this posting is about it.

Android App Build Environment

  1. Ant
    Basically, Android started this tool. I used to automation build in Jenkins (CI) and to release. but I rarely used in development.
  2. Eclipse
    Many developer used this IDE. In SingleDex, It was good tool. Actually, It was pretty good to build for Incremental.
  3. Gradle-Android Studio
    Android Studio is based on Gradle. If developer change to gradle properties, then they always sync gradle to AS. and Gradle have to learn. also Gradle was so slow.

After last year I used AS & IntelliJ, Gradle’s performance was always complaint. But many tech-companies in Silicon Valley, they tried another solution.

New Android App Build

  1. Bazel (by Google, Github)
    It is not only for android. It can build for iOS. Bazel started from Blaze (Google’s Build System). Bazel is on Beta.
  2. Buck (by Facebook, Github)
    Buck support more languages, platforms than Bazel. (Go, Rust, etc…)
  3. Pants (by Twitter, FourSquare, Square, Github)
    3 big companies work together. (sorry, I don’t know many things.)

Performance

1. Bazel

source : Bazel (http://bazel.io/docs/mobile-install.html)

2. Buck

source : Buck (https://buckbuild.com/article/exopackage.html)

3. Pants

I cannot find datas.

Why do we move gradle to other build tool?

In gradle team’s blog

Gradle Team Perspective On Bazel 03, 2015
https://gradle.org/gradle-team-perspective-on-bazel/

they picked Bazel’s short point

1. Bazel does not have a high level declarative build language that makes the build easy to use for developers.
2. Not built for extensibility*.
3. first is central repo, after performance.
4. Bazel is *nix only, it does not run on Windows.
5. No plugin ecosystem.

Conclusions

New Build Systems (Bazel, Buck) show better than gradle. but they are too difficult for initialize. so I didn’t move gradle to buck or something else.

but After move to Buck or Bazel, Pants, some developers say it was so efficient to save time for building. (I lost reddit posting. sorry.)

The Solution is only moving build tool?

from Alan Jeon of GDG Korea Android Member, I improved to build.

1. Update Gradle

$> $project/gradle/wrapper/gradle-wrapper.properties// ...
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip

2. update Android Plugin in build.gradle

buildscrpt {
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}

3. set minSdk in build.gradle (★★★)

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

android {
productFlavors {
dev {
minSdkVersion 21
}
prod {
minSdkVersion 14
}
}
}

Packaging process is two step. one is class to dex. other is merging dex. but after api 21 (Lollipop) is based on ART. so It doesn’t do merging dex. It is keypoint to save building time.

but Be careful. after changing minsdk value, AS wouldn’t warn api level.

4. add gradle.properties

org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx768m

5. add DexOptions in build.gradle

android {
dexOptions {
incremental true
}
}

※incremental has potential error. (참고링크)

Performance

Build Device : MacBook Pro Retina 2012 (i7 2.3Ghz, 8GB Ram)

Before

Clean Build : 56.97s
Incremental Build : 16.3s

After

Clean Build : 47.0s (up to 17% )
Incremental Build : 9.58s (up to 41%)

※ in MultiDex, Incremental build was improved 47 sec to 17 sec.

in Iterative Development (included TDD), I try to improve build. I hope helpful to many developer.

--

--