The Build Side of
an Android App
Nikita Kozlov
Zalando SE
@Nikita_E_Kozlov
Boris Farber
Google
@borisfarber
Slide 2
Slide 2 text
Background
● Build improvement is the most requested feature from developers
● Worked with a few companies to speed up their builds
● Share best practices and patterns
Slide 3
Slide 3 text
Problem
● You add new features, libraries and frameworks.
● You refactor your code to smaller classes, add tests
● Somehow, the build times add up
Slide 4
Slide 4 text
We don’t think about our build as a design
component
Slide 5
Slide 5 text
Build challenge
● Analysing build takes time
● Difficult to estimate and prioritize
● Build improvement might be ambiguous
Slide 6
Slide 6 text
Focus on following
● Build Tools versions
● Hardware
● Modularization
Slide 7
Slide 7 text
Our process
Create a test project
Implement suggestion
Test & Measure
Implement within a real project
Android Studio Poet
Gradle Profiler*
Slide 8
Slide 8 text
Incremental build
change a Java/Kotlin
file
assembleDebug
Slide 9
Slide 9 text
Build Tools versions
Slide 10
Slide 10 text
Versions we tested
● Gradle: 4.3.1 to 4.8
● Android Gradle Plugin: from 3.0.1 to 3.1.2
● Kotlin: from 1.1.60 to 1.2.50
Slide 11
Slide 11 text
What about Build Tools versions?
2x speed up
just from the
build tools
Slide 12
Slide 12 text
Another easy win
From the build scan:
● Compilation - 35%
● Dexing - 55%
Slide 13
Slide 13 text
Dexing is a limiting step
.CLASS
.CLASS
.CLASS
.DEX
.DEX
.DEX
Will be faster if
min SDK is 21
.CLASS
Slide 14
Slide 14 text
Incremental build with min SDK 21
Set min SDK to 21 during
development to increase your
build speed
Compile Avoidance
App
Feature
Incremental build after
a change of method’s
body in Feature: 8s
Incremental build after
a adding a public
method to Feature: 10s
Slide 22
Slide 22 text
Extracting rarely-changed code reduces build time
App
Incremental build with
a change in App: 55s
Incremental build with a
change in App: 39s
App
Utils
Slide 23
Slide 23 text
Work against tests whenever you can
App
Incremental build of App
with a change in App: 55s
Incremental build of Utils
module: 26s
App
Utils
Slide 24
Slide 24 text
Change in the library module vs application module
App
Utils
Incremental build of App
module: 39s
Incremental build of Utils
module: 26s
Slide 25
Slide 25 text
Intermodule dependencies increase build time
Incremental build with
change in Feature 3: 1m 5s
Incremental build with
change in Feature 3: 1m 11s
Feature 1
Feature 3
Feature 2
App
Feature 2
Feature 3
Feature 1
App
Slide 26
Slide 26 text
Start simple if you don’t have time
App
Tracking
Utils
Core UI
Networking
App
Feature
Feature
Feature
Common code
Slide 27
Slide 27 text
Use a topology that works for you
App
App
Monolith
Incremental build with
change in App: 81s
Incremental build with
change in Main: 92s
Slide 28
Slide 28 text
Use a topology that works for you
App
Feature
App
Monolith
Feature
Incremental build with
change in Feature: 10s
Incremental build with
change in Feature: 7s
Slide 29
Slide 29 text
Modularization rules of thumb
● Extract utils and other rarely-changed code
● Keep in mind the intermodule dependencies
● Developing library modules in TDD way helps
● Measure on a test project first
Slide 30
Slide 30 text
Our process
Create a test project
Implement suggestion
Test & Measure
Implement within a real project
Android Studio Poet
Gradle Profiler
Slide 31
Slide 31 text
● Tool to generate large self contained Android projects
● https://github.com/android/android-studio-poet
● Accepts JSON config file for the parameters
Android Studio Poet
Learn more
● Extend Android Studio Poet -
https://github.com/android/android-studio-poet/blob/master/exten
d/Extending.md
● For this talk we made about 50 configs and more then 500 builds
● Our configs, we used for this presentation
https://github.com/android/android-studio-poet/tree/master/config
s
Slide 36
Slide 36 text
Thanks !
And to Sergio Murguia, Google and Stefan Oehme, Gradle
Slide 37
Slide 37 text
Questions ?
Nikita Kozlov
Zalando SE
@Nikita_E_Kozlov
Boris Farber
Google
@borisfarber