Slide 1

Slide 1 text

A Complete Journey of Android Modularisation Sinan Kozak Twitter - @snnkzk

Slide 2

Slide 2 text

2 Single module code base Nothing wrong with having a single module

Slide 3

Slide 3 text

3 Legacy code base • There might be one or two giant modules • Lots of features in same module • Build times are longer than your lunch time

Slide 4

Slide 4 text

4 1 Code conflict No clear ownership 4 Long build time 2 High coupling 3 What problems can modularisation solve?

Slide 5

Slide 5 text

5 Modularise all the things But how? Photo by Tanalee Youngblood on Unsplash

Slide 6

Slide 6 text

6 What needs to be a module Modules for software architecture? Modules per feature? Photo by Sarah Arista on Unsplash

Slide 7

Slide 7 text

What is a good modularisation layering? https://www.droidcon.com/2019/11/15/android-at-scale-square

Slide 8

Slide 8 text

8 My suggestions for modularisation • Public API module per feature • Implementation modules per public API • Fakes implementation for tests • Almost empty app module

Slide 9

Slide 9 text

9 What is the goal? • Boundaries between features • How many modules per team? • Better build times • How fast is enough? • Isolated tests • What will be the cost?

Slide 10

Slide 10 text

10 Possible metrics to track • Lines of code per module • Keep splitting biggest module • Build time • Repeatable build scenarios • Dependency depth • CPU utilisation

Slide 11

Slide 11 text

11 CPU utilisation

Slide 12

Slide 12 text

12 CPU utilisation

Slide 13

Slide 13 text

13 What were our goals? • Maximise CPU utilisation • Flatter dependency graph • Increase isolated UI test count

Slide 14

Slide 14 text

Convention plugin Source of truth for library gradle setup

Slide 15

Slide 15 text

15 Convention plugin ● Set min, target and compile sdk at first ● Write plugin as included build

Slide 16

Slide 16 text

Maintenance and Modernisation What is next after modularisation?

Slide 17

Slide 17 text

17 Maintenance and Modernisation

Slide 18

Slide 18 text

18 Modernisation • Template module • Configuration cache • Namespaced R file • Cache usage and incremental build improvements • Build performance regression detection

Slide 19

Slide 19 text

Navigation How to open different features?

Slide 20

Slide 20 text

20 Activity navigation • Intent needs class or class path • Deeplink - App-link? • Input for next activity? • Animation?

Slide 21

Slide 21 text

21 Fragment navigation • In feature fragment navigation is different than cross feature fragment navigation • AndroidX Navigation? • XML doesn’t work • Nav Graph DSL and Deeplink • Passing input needs to be simplified

Slide 22

Slide 22 text

22 Use purposeful name Common, core, base are not good names

Slide 23

Slide 23 text

23 Split the legacy Do not keep reusing a messy legacy module Create new modules for the part you need Photo by Brina Blum on Unsplash

Slide 24

Slide 24 text

24 New module for new code Use smaller modules to contain different logic based on they do Keep them in isolation to increate reuse Photo by Sen on Unsplash

Slide 25

Slide 25 text

25 Learning curve 01 02 03 Explain with visual https://github.com/vanniktech/gradle- dependency-graph-generator-plugin Lint checks https://github.com/autonomousapps/ dependency-analysis-android-gradle- plugin Graph assertion https://github.com/jraska/modules- graph-assert Photo by Drew Beamer on Unsplash

Slide 26

Slide 26 text

26 Where to start • Move all the code in app module to a library • New features are great candidates • Extract reusable code pieces to new module

Slide 27

Slide 27 text

27 Team can quickly add new features or delete old ones while building faster Faster delivery Features can live without depending on each other’s implementation Less conflict Modules have clear names and responsibilities Clear ownership

Slide 28

Slide 28 text

28 Summary • Modularisation is a mental modal • Creating new module should be habit • Be careful to not end up with worse than what you started • Track your progress

Slide 29

Slide 29 text

Thank you! Q/A Sinan Kozak Twitter - @snnkzk