Modularization is essential in any professional Android codebase, and there are compelling reasons to implement it, some of which will be discussed in this post. It's important to note that our focus here is on feature-based modularization. While some developers prefer modularization based on concerns like UI, domain, and data, following the Clean Architecture pattern, this post specifically addresses modularizing an app by features, with separate modules for UI, domain, and data contained within a feature module. Even though this approach might result in a higher number of modules, it offers a clearer project overview and simplifies unit testing. Here are some of the benefits:
1 - Faster Gradle builds:
Gradle rebuilds the entire module whenever a build is requested. This underscores the importance of modularizing your app, especially as your codebase expands with each added feature. Without modularization, build times can become a significant challenge. However, in a modularized app, only the affected modules need to be rebuilt, streamlining the development process and saving you valuable time.
2 - Reusability:
A module acts as a fundamental building block. Isolating these modules simplifies the process of 'composing' other products using the existing pieces, effectively preventing code duplication and minimizing potential maintenance challenges. Keeping them as separate components makes maintenance significantly more manageable.
3 - Visibility control:
Modularization effectively utilizes the internal
visibility modifier, aligning seamlessly with this concept by restricting the visibility of specific classes and functions to only their respective modules. This approach is particularly beneficial when you aim to prevent unnecessary exposure of certain files to modules where they don't belong, ultimately enhancing the development experience, including more refined autocomplete suggestions in Android Studio.
4 - On-Demand features:
By leveraging the advanced capabilities of app bundles, you have the option to distribute your app with only its essential features. This approach proves valuable when only a small percentage of your users necessitate access to exclusive features, such as admin moderation or less frequently used functionalities. Consequently, this reduces the app's size for those who don't require access to the full spectrum of features.
5 - Work delegation:
In the context of modularization by feature, each squad, team, or tribe can exclusively focus on their respective modules. This approach minimizes conflicts and ensures a clear separation of concerns within your product's development team.
6 - Android ecosystem expansion:
Picture this scenario: your product manager informs you that the next significant step in the product you're working on involves integrating with Android Auto/Wear OS/Android TV. While it may initially appear to be a daunting task, modularization simplifies the process. You can seamlessly 'assemble' your new module by leveraging the features that already exist in the modules you've previously developed. This way you would only need to create the new UI-exclusive module since all the hard work and logic is already done by the non-UI modules.
Extra - Kotlin Multiplatform Mobile:
Having a modularized codebase simplifies the process of transitioning an existing app built with native technologies into a Kotlin Multiplatform Mobile application. As long as your non-UI modules are not dependent on Android-specific libraries, you can seamlessly migrate them to Kotlin Multiplatform Mobile modules. The best part is that this approach is compatible with both Android and iOS applications.
Conclusion:
Modularizing your app offers numerous advantages, as mentioned earlier, from reducing build times to creating a more organized and efficient work environment. In today's Android development landscape, it has become essential for every developer to gain experience in modularization. Don't miss the opportunity to enhance your skills and make it a part of your toolkit.