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

Practical Modularisation for Android Developers

Practical Modularisation for Android Developers

How can you use Gradle and an extremely opinionated module structure to reduce your build times?

Jordan Terry

April 21, 2022
Tweet

More Decks by Jordan Terry

Other Decks in Programming

Transcript

  1. Agenda • Introduction • What is modularisation? • What is

    your codebase? • Cohesion, Coupling & Gradle • Build times • Reusability • Defining a strategy • Questions? 2
  2. 6

  3. What is your codebase? 10 • Define a way to

    measure modularisation • Apply that to your codebase
  4. 12 Monolithic Modular What is your codebase? = code base

    with a module that takes more time to compile than other modules = code base with no modules that take more time to compile than the sum of other modules
  5. 15

  6. 20 import ':app' import ':login' import ':profile' import ':networking' import

    ':okhttp' settings.gradle.kts app/ -> login/ -> src/ -> build.gradle.kts -> profile/ -> src/ -> build.gradle.kts -> networking/ -> src/ -> build.gradle.kts -> okhttp/ -> src/ -> build.gradle.kts -> settings.gradle.kts app/ -> login/ -> src/ -> build.gradle.kts -> profile/ -> src/ -> build.gradle.kts -> networking/ -> src/ -> build.gradle.kts -> okhttp/ -> src/ -> build.gradle.kts -> settings.gradle.kts app/ -> login/ -> src/ -> build.gradle.kts -> profile/ -> src/ -> build.gradle.kts -> networking/ -> src/ -> build.gradle.kts -> okhttp/ -> src/ -> build.gradle.kts -> settings.gradle.kts app/ -> login/ -> src/ -> build.gradle.kts -> profile/ -> src/ -> build.gradle.kts -> networking/ -> src/ -> build.gradle.kts -> okhttp/ -> src/ -> build.gradle.kts -> settings.gradle.kts build.gradle.kts plugins { id("kotlin-android") } android { ... } dependencies { ... } Defining Modules
  7. Incremental Build times 27 • How important are build times?

    • When incremental build times go wrong • Some tips on cohesion
  8. Build times 600 engineers * $1.42/minutes * 42 builds/week *

    44 work weeks/year = $1,600,000/year 31 Gradle vs Maven: Performance Comparison - https://gradle.org/gradle-vs-maven-performance/ Money Saved Equation
  9. :timelines :profile :login :network models 32 Build times - comparing

    structures :app :timelines :login :profile :networking :networking :network models
  10. :timelines :login :login models :profile models :timeline models :profile :networking

    33 Build times - comparing structures :app :timelines :login :profile :networking :login models :profile models :timeline models :json
  11. :timelines :profile :okhttp-4 :login Reusability - Third Parties 36 :timelines

    :login :profile :okhttp-3 :okhttp-4 :networking :networking :okhttp-3
  12. :navigation :navigation jetpack :navigation compose :login :timelines :timelines :login :profile

    :profile Reusability - APIs & Implementations 37 :navigation :api :navigation: impl compose :navigation: impl jetpack :navigation :impl