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

Practical Modularisation for Android Developers

Practical Modularisation for Android Developers

Modularisation isn't a magic wand. Breaking a monolith to more modules isn't a shortcut to better build speed and organised code.

To reap the real benefits of modularisation we must modularise with a purpose. That is, to create a plan and break the code base up piece by piece.

My aim with this presentation is to help you do this. I want to give you a mental model you can apply to your own apps. Then, I will show you patterns we can apply. I'll also show you the benefits of applying abstraction to your modules by creating api and implementation modules.

We'll also look at IDE tooling to make applying these patterns easier and making modularisation.

Finally, we will look at the building blocks needed to plan your modularisation.

554f9af657e790ecd391807b95a8ff4d?s=128

Jordan Terry

April 22, 2022
Tweet

Other Decks in Programming

Transcript

  1. Practical modularisation for Android developers Jordan Terry 1

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

    your codebase? • Cohesion, Coupling & Gradle • Build times • Reusability • Defining a strategy • Questions? 2
  3. 3 Introduction 🇹 Then Now 2015 2018 2021 @JordNullable

  4. What is modularisation? 4

  5. 5 What is modularisation? Large system Modules

  6. 6

  7. 7 Android modularisation Large System Modules Codebase Gradle Modules

  8. Talking about modularisation 8

  9. The benefits of modularisation 9 Build Times Reusability

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

    measure modularisation • Apply that to your codebase
  11. 11 Monolithic Modular What is your codebase? You are somewhere

    here…
  12. 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
  13. What is your codebase? 13 Monolithic Modular

  14. 14 Monolithic Very Modular What is your codebase? Modular

  15. 15

  16. Cohesion, Coupling & Gradle 16

  17. High Cohesion Low Cohesion Cohesion 17 Low Cohesion High Cohesion

  18. High Coupling Low Coupling Coupling 18 Low Coupling High Coupling

  19. Gradle 19 • Module definition • Connecting Modules • Incremental

    Compilation
  20. 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
  21. 21 :networking :login :profile :okhttp :app Defining modules

  22. dependencies { implementation project(":login") implementation project(":profile") } 22 app/build.gradle.kts Connecting

    modules
  23. 23 :networking :login :profile :okhttp :app Connecting Modules

  24. :profile :profile 24 :profile Incremental compilation

  25. :login :profile :profile :login :networking :networking 25 :okhttp :app Incremental

    compilation
  26. The benefits of modularisation 26 Build Times Reusability

  27. Incremental Build times 27 • How important are build times?

    • When incremental build times go wrong • Some tips on cohesion
  28. XKCD 303 - https://xkcd.com/303/ 28 Build Times

  29. @vRallev on Twitter - https://mobile.twitter.com/vRallev/status/1485430862850125824 29 Build Times

  30. @softwarejameson on Twitter - https://twitter.com/softwarejameson/status/1455971162060697613?lang=en 30 Build Times

  31. 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
  32. :timelines :profile :login :network models 32 Build times - comparing

    structures :app :timelines :login :profile :networking :networking :network models
  33. :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
  34. Reusability 34 • What are reusable components • Reusable libraries

    • Reusable modules
  35. Reusability 35 OkHttp Play Billing Toast API

  36. :timelines :profile :okhttp-4 :login Reusability - Third Parties 36 :timelines

    :login :profile :okhttp-3 :okhttp-4 :networking :networking :okhttp-3
  37. :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
  38. A modularisation strategy 38 • Training • Discipline ◦ Cohesion

    & Coupling
  39. Coming up with a plan 39 :foundation :feature :feature :feature

    :feature High Cohesion Low Coupling
  40. Where to find me? 40 • @JordNullable

  41. Any questions? 41