Android Multi-module Structure (Part -1)

Noban Hasan
3 min readApr 19, 2022

--

simple diagram of multi module structure

What is Module in Android?

From my opinion if I want to describe in one line then A module is a sub part of full application”.

A module is independent project. In Android project we can create lots of sub modules. Each module can have their own responsibility for their particular task or feature.

For example if you already done some android project you should use some third party library. Those library are modules. We use them for doing some features and task as per we need.

So when we are developing an Application we also can create some module and use them in our App as dependency. This is called modulazation.

Now we can see the definition of module from Android developer documentation

A module is a collection of source files and build settings that allow you to divide your project into discrete units of functionality. Your project can have one or many modules, and one module may use another module as a dependency. You can independently build, test, and debug each module.

Additional modules are often useful when creating code libraries within your own project or when you want to create different sets of code and resources for different device types, such as phones and wearables, but keep all the files scoped within the same project and share some code.

Reference : https://developer.android.com/

Why we will use multi-module in Android Application ?

There are so many benefits of using multi module structure. Now I will shortly describe some good points of using multi module.

Faster build and execution time: In multi module application all dependency are separated in multiple Gradle. If the Gradle task is separated in each module the build time will faster because if there is no change in another modules the app will not run that Gradle task from that module.

You can save lots of time when developing with this approach.

Loose coupling code: Every module is separated by some responsibility and feature. So in every module code are also separated and non dependent . You can easily add a feature and do some testing in specific module.

Code Reusability : Code reusability is an important fact when you work on a big project. If you make a module that can be used in many projects so you can make that project as a library. So you can use them in future projects.

Dynamic features: It’s a very good advantage of multi-module structure. Suppose you have future feature you already done. But you don’t want to add this feature in current release.

With this approach it’s easy you can just exclude that features module from the project. You can include this module in future. It’s simple and easy. No need to commenting out the thousand lines of code.

Readability: In single module if there is lots of xml file in resource folder. Sometimes it’s hard to find out the layout.You cant make a package or directory in res folder.

For this case it you create multiple modules for each features then all xml file will separate modules res folder. That’s why it increase the readability.

Maintainability :In case of complex code scenario or business logic implementation modular architecture is a great solution. It can break down the bigger task into a small sub model for achieving milestone . So for future up-gradation it become so much easier to maintaining the codebase.

Build apk of each module : If you create some module in Android project you can easily create an apk form that module. You can give that apk to QA for specific feature only. It’s also a time saving process for QA for testing that feature.

In next part I will try to describe more with a simple base digram with example of Android.

--

--