Slide 1

Slide 1 text

Practical modularisation for Android developers Jordan Terry 1

Slide 2

Slide 2 text

Agenda ● Introduction ● What is modularisation? ● What is your codebase? ● Cohesion, Coupling & Gradle ● Build times ● Reusability ● Defining a strategy ● Questions? 2

Slide 3

Slide 3 text

3 Introduction 🇹 Then Now 2015 2018 2021 @JordNullable

Slide 4

Slide 4 text

What is modularisation? 4

Slide 5

Slide 5 text

5 What is modularisation? Large system Modules

Slide 6

Slide 6 text

6

Slide 7

Slide 7 text

7 Android modularisation Large System Modules Codebase Gradle Modules

Slide 8

Slide 8 text

Talking about modularisation 8

Slide 9

Slide 9 text

The benefits of modularisation 9 Build Times Reusability

Slide 10

Slide 10 text

What is your codebase? 10 ● Define a way to measure modularisation ● Apply that to your codebase

Slide 11

Slide 11 text

11 Monolithic Modular What is your codebase? You are somewhere here…

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

What is your codebase? 13 Monolithic Modular

Slide 14

Slide 14 text

14 Monolithic Very Modular What is your codebase? Modular

Slide 15

Slide 15 text

15

Slide 16

Slide 16 text

Cohesion, Coupling & Gradle 16

Slide 17

Slide 17 text

High Cohesion Low Cohesion Cohesion 17 Low Cohesion High Cohesion

Slide 18

Slide 18 text

High Coupling Low Coupling Coupling 18 Low Coupling High Coupling

Slide 19

Slide 19 text

Gradle 19 ● Module definition ● Connecting Modules ● Incremental Compilation

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

21 :networking :login :profile :okhttp :app Defining modules

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

:profile :profile 24 :profile Incremental compilation

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

The benefits of modularisation 26 Build Times Reusability

Slide 27

Slide 27 text

Incremental Build times 27 ● How important are build times? ● When incremental build times go wrong ● Some tips on cohesion

Slide 28

Slide 28 text

XKCD 303 - https://xkcd.com/303/ 28 Build Times

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

:timelines :profile :login :network models 32 Build times - comparing structures :app :timelines :login :profile :networking :networking :network models

Slide 33

Slide 33 text

: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

Slide 34

Slide 34 text

Reusability 34 ● What are reusable components ● Reusable libraries ● Reusable modules

Slide 35

Slide 35 text

Reusability 35 OkHttp Play Billing Toast API

Slide 36

Slide 36 text

:timelines :profile :okhttp-4 :login Reusability - Third Parties 36 :timelines :login :profile :okhttp-3 :okhttp-4 :networking :networking :okhttp-3

Slide 37

Slide 37 text

: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

Slide 38

Slide 38 text

A modularisation strategy 38 ● Training ● Discipline ○ Cohesion & Coupling

Slide 39

Slide 39 text

Coming up with a plan 39 :foundation :feature :feature :feature :feature High Cohesion Low Coupling

Slide 40

Slide 40 text

Where to find me? 40 ● @JordNullable

Slide 41

Slide 41 text

Any questions? 41