Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Faster builds on Android - from 2 minutes to 2 seconds

Faster builds on Android - from 2 minutes to 2 seconds

What does a developer do when a build takes 2 minutes? He gets bored and his mind starts to wander. Maybe he opens Reddit, Twitter orMedium or checks his emails. Switching context and multitasking kills productivity. Every developer needs fast feedback, so he can get jump into the flow state. Therefore, fast builds are essential for productive development.

First, we take a look into Gradle Build Scans. There is no sense in accelerating your build without measuring and comparing the different outcomes. Gradle Build Scans help you to understand what happens during your build and which parts consume the most time.

Then we continue with basic tips to tweak your build with Gradle. Most of those tips are quick wins, because they only require a simple change in the Gradle build settings.

Finally, we take a look into how modularisation influences the build speed by an example. Doing it right you can change your business logic and run your tests in 2 seconds instead of 2 minutes.

Philipp Hofmann

September 09, 2019
Tweet

More Decks by Philipp Hofmann

Other Decks in Technology

Transcript

  1. What do you do when you have to wait 2

    minutes? Photo by NordWood Themes on Unsplash
  2. • Measure Your Builds • Quick Wins to Fasten Your

    Builds • Modularisation and Build Speed • Some additional information about the topic on the chart • Maybe some numbers or a background information about some insights • Here is just another placeholder text to visualise the look of a filled info box INFO BOX Topics
  3. $ ./gradlew assembleDebug --scan BUILD SUCCESSFUL in 1s 84 actionable

    tasks: 84 up-to-date Publishing a build scan to scans.gradle.com requires accepting the Gradle Terms of Service defined at https:// gradle.com/terms-of-service. Do you accept these terms? [yes, no]
  4. $ ./gradlew assembleDebug --scan BUILD SUCCESSFUL in 1s 84 actionable

    tasks: 84 up-to-date Publishing a build scan to scans.gradle.com requires accepting the Gradle Terms of Service defined at https:// gradle.com/terms-of-service. Do you accept these terms? [yes, no] yes
  5. $ ./gradlew assembleDebug --scan BUILD SUCCESSFUL in 1s 84 actionable

    tasks: 84 up-to-date Publishing a build scan to scans.gradle.com requires accepting the Gradle Terms of Service defined at https:// gradle.com/terms-of-service. Do you accept these terms? [yes, no] yes Gradle Terms of Service accepted.
  6. $ ./gradlew assembleDebug --scan BUILD SUCCESSFUL in 1s 84 actionable

    tasks: 84 up-to-date Publishing a build scan to scans.gradle.com requires accepting the Gradle Terms of Service defined at https:// gradle.com/terms-of-service. Do you accept these terms? [yes, no] yes Gradle Terms of Service accepted. Publishing build scan...
  7. $ ./gradlew assembleDebug --scan BUILD SUCCESSFUL in 1s 84 actionable

    tasks: 84 up-to-date Publishing a build scan to scans.gradle.com requires accepting the Gradle Terms of Service defined at https:// gradle.com/terms-of-service. Do you accept these terms? [yes, no] yes Gradle Terms of Service accepted. Publishing build scan... https://gradle.com/s/glklref6wdxr6
  8. • Gradle • JVM • Android Studio and SDK Tools

    • Android Plugin for Gradle Update
  9. If neither a task’s inputs nor its output have changed

    since the last time it was run, Gradle will not run it again.
  10. flavorDimensions "mode" productFlavors { dev { dimension "mode" resConfigs "en",

    "xxhdpi" buildConfigField "long", "TIMESTAMP", "0L" } full { dimension "mode" } }
  11. Quick wins 1. Update your Tools 2. Use Apply Changes

    3. Caching 4. Incremental Compilation 5. Parallel Builds 6. Build Variant for Develop Photo by Richard R Schünemann on Unsplash
  12. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply

    plugin: 'maven-publish' apply plugin: 'kotlin-kapt' apply plugin: 'talaiot' apply plugin: 'io.gitlab.arturbosch.detekt' apply plugin: 'org.jlleitschuh.gradle.ktlint'
  13. 19 tips for Gradle in Android projects — 2019 Edition

    https://medium.com/google-developer-experts/19-tips-for-gradle-in-android- projects-2019-edition-11af704eb06e
  14. Optimise • Update gradle and gradle plugin • Update Kotlin

    • Enable parallel builds and incremental compilation • Split up code into multiple modules
  15. Module A Module B Module C Foo implementation Module A

    Module B Module C Foo api ModuleB is part of my Public API ModuleB is my Implementation Detail
  16. Module A Module B Module C Foo implementation Module A

    Module B Module C Foo api ModuleB is part of my Public API ModuleB is my Implementation Detail
  17. Module A Module B Module C Foo implementation Module A

    Module B Module C Foo api ModuleB is part of my Public API ModuleB is my Implementation Detail
  18. Build just what you need • Build only the code

    you want to check. • Let you iterate faster on your feature modules.
  19. Advantages of Multiple Modules 1. Build modules in parallel 2.

    Compilation avoidance 3. Faster tests 4. And all the other advantages … (Reusability, Maintainability, SOLID, …)
  20. Photo by Richard R Schünemann on Unsplash Quick wins 1.

    Update your tools 2. Use Apply Changes 3. Use Gradle caching 4. Incremental compilation 5. Parallel builds 6. Build variant for develop