The gritty truth about app modularisation — part 3

Mark Ng
Mark Ng
Nov 8 · 4 min read

During stages 1,2 & 3 of our modularization work, we used the following tips and tricks to help get the job done quicker.

Tips & Tricks

  1. Build Config — Although the code of the left compiles it throws an exception at runtime.

2. Javadoc can also pull in imports — Make sure that your imports are being used in your code and not only in your Javadoc.

3. Android Studio refactoring — If you need to change your package structure do it within the module before moving your code. When moving code from one module to another where the package structure stays the same, use the move by directory option (the second option).

4. Move layouts first — It will help you identify the other resources such as strings and images that you will also need to move.

5. Extra constants should not be on the activity — This adds your activity as a dependency.

6. Declare constants in a separate object — Same as the previous tip but for other objects.

7. Check imports for dependencies — This will help you work out how to break up your module or which modules you will need to use.

8. Check injection for dependencies

9. Circular dependencies can be broken by splitting modules into finer grain modules

10. Circular dependencies can be broken by using interfaces

11. Use an interface for navigation

12. When moving code you may get weird build or compile issues that don’t make sense. In this case, try removing the gradle build cache in your home directory E.g. /Users/markng/.gradle/caches/build-cache-1

Result

Before we started we had 700+ lines in our Strings.xml file, 300+ lines in our AndroidManifest.xml and 125 layouts in layout directory. Since modularising our code we no longer have any monolithic files, our modules are small and simple to understand. It really makes it easier to find things and reduces the cognitive load on developers when making changes.

Here is what our files look like for the more module in our app.

Gradle file

As you can see our Gradle build files are very minimal and the dependencies on the other modules are clearly defined.

AndroidManifest

The AndroidManifest only includes activities for this module, through the merging process this configuration will be combined into the main AndroidManifest file.

String values

Each of our UI modules has 2 String files one for analytics and the other for the text which is used on our UI screens.

Conclusion

Just like these articles, modularization is a very long and tiring journey. If you do make it to the end there are many great benefits that your developers will be grateful for. If you work on a flagship app and have 3 or more developers then I believe that modularization is a must and its a question of not if but when you start. The sooner the better then you get to work on other great new features in Android.

Thanks to karl

Mark Ng

Written by

Mark Ng

Android Platform Manager @Auspost

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade