Android

Google publishes a guide to the modular structure of Android apps

Google recently released a guide to modularizing Android apps. This guide is designed to provide best practices and recommended patterns for developers to build multi-module Android apps, with an emphasis on mitigating issues that arise as the codebase grows, such as scalability, readability, stability, and testability.

After a survey asking developers about their experience with modularization, where 54% of participants said it was difficult to find good learning materials about modularization, and nearly 95% claimed that the material available on developer.android.com was insufficient, Google decided to launch a guide to the modularization of Android apps. It is important to note that the guide is aimed at intermediate and advanced developers, who are usually familiar with the recommended app architecture.

According to Google, some of their apps already use modularization, such as Play Store, Google News and YouTube.

Modularization is a practice of organizing the codebase into loosely coupled parts, usually called modules. Each module should be independent and designed to serve a clear purpose.

(image taken from https://developer.android.com/topic/modularization)

Modularization brings many benefits; modules reduce design complexity, making it easier to maintain and develop large systems. Let’s look at some of these benefits:

  • Reusability: offers the ability to share code and build multiple apps with the same module; an app should be the sum of many modules, each module containing specific functions
  • Strict Visibility Control: Allows developers to easily control what should be exposed to other parts of the codebase and modules
  • Customizable Delivery: Play Feature Delivery allows developers to deliver specific features of the app conditionally or on demand

Other benefits can be easily achieved when using modularization. They are:

  • Scalability: When a project is modularized appropriately, there is usually a principle of separation of concerns and a loosely coupled code base, making the system easier to maintain and develop
  • Ownership: Modules can be used to enforce accountability, with a dedicated owner responsible for maintaining the code, fixing bugs, adding tests, and reviewing changes
  • Encapsulation: meaning that modules should have the least possible amount of knowledge about other parts. Isolated code makes it easier to read, understand and evolve
  • Testability: the ability to test the code; it is easier and faster to test modules than to test a large tightly coupled system
  • Build time: related to incremental build, build cache or parallel build some Gradle features can take advantage of modularity to improve build performance

Google has made the Now in Android multi-module app available in a GitHub repo, with a handy modular path that outlines what the modules do and how they interact with each other.

The guide also includes a section related to common modularization patterns, where you can learn more about low coupling and high cohesion, data modules, function modules, app modules, common modules, and so on.

Leave a Comment