Modularization. Part 3. Compilation time
This series consist of
- Part 1 — Application structure overview
- Part 2 — Dagger structure
- Part 3 — Compilation time
Let’s see how multi-module project affects build time. I will compare two different Android Gradle plugin versions 2.3.3
and 3.0.0-beta7
. Generated profile (via --profile
option) allows to see exact tasks that are executed.
How you assemble matters
Version 2.3.3./gradlew clean assembleDebug — profile
~28 sec./gradlew clean :app:assembleDebug — profile
~ 18 sec
My assumption is the following. :app:assembleDebug
compiles app
module and all dependent modules. In case of clean build, all of them.
Plain assembleDebug
do same as :app:assembleDebug
plus :persistence:assembleDebug
, :base-app:assembleDebug
etc. This introduces additional actions which blows up build time.
Version 3.0.0-beta7
./gradlew clean assembleDebug — profile
~13 sec./gradlew clean :app:assembleDebug — profile
~ 13 sec
Latest plugin version not only faster but also “smarter”. The difference is visible when we compare profile. :app:assembleDebug
executes less tasks than assembleDebug
. And version 3.0.0 assembleDebug
executes less tasks than version 2.3.3 assembleDebug
.
Flavors and build types
Let’s take a close look at the generated profile. Version 2.3.3 :app:assembleDebug
contains task :user-details:compileReleaseKotlin
. That’s strange since we are compiling debug build. Version 3.0.0 contains :user-details:compileDebugKotlin
, which is more logical. Same happens with flavors. Versions 3.0.0 can properly propagate compiled flavor to all app-modules. Before all flavors were compiled regardless your choice.
Incremental compilation.
Let’s see how incremental compilation is influenced by module division. When we change LoginActivity
from login
module, only login
and app
modules are recompiled. All other modules are “UP-TO_DATE”. When we change Storage
from persistence
module, all dependent modules (login, base-app
, user-details
) are recompiled. Navigator modules are not recompiled because they do not depend on persistence
module.
Summary
- Only affected code is recompiled. It’s possible to achieve huge build time improvement, by creating multiple small independent modules.
- Use latest Android Gradle plugin version. Version 3.0.0 has a lot of improvements and bugfixes for multi-module projects.
Project can be found on Github.