Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Dis-) Advantage of having multiple modules in an Android Studio Project?

Is it advantageously to have multiple modules in an Android Studio Project over having only a single large app-module?

I know about Android Modules in general and the advantages of SOLID so my focus is especially considering build performance. As gradle can do incremental builds, and if only one module changes, those other modules don't need to be processed?

Is this noticeable or is there even a considerable amount of overhead?

like image 260
Tobias Avatar asked Jan 13 '17 10:01

Tobias


People also ask

What is multi module project in Android?

A project with multiple Gradle modules is known as a multi-module project. In a multi-module project that ships as a single APK with no feature modules, it's common to have an app module that can depend on most modules of your project and a base or core module that the rest of the modules usually depend on.

What is use of module in Android Studio?

Modules provide a container for your app's source code, resource files, and app level settings, such as the module-level build file and Android manifest file. Each module can be independently built, tested, and debugged. Android Studio uses modules to make it easy to add new devices to your project.

What is Library module in Android Studio?

An Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest.

What is modular programming in Android?

Wikipedia. You can think of modularization like turn some of your packages into small reusable pieces of code across your application. The modules you are going to create can be android libraries, pure kotlin/java libraries, more app modules, wearable modules, auto modules etc.


2 Answers

It is of great advantage to have multiple modules rather than to create a single large app-module. Following are the key points:

  1. If you find the compile time is taking longer then you can disable the module from gradle you are not working upon temporarily and compile it faster.
  2. A module helps us to divide project into discrete units of functionality also. You can create one data module which contains all pure java beans and can be used by multiple app if you are in same domain. Eg. Finance domain can have two applications one for viewing policies for customer and other can be for an insurance agent for viewing the same data. But the data module can be shared across all apps and even the data module can be borrowed from server or API team. Data module can be tested individually without any android dependencies and any one knows about java can write test cases.
  3. Each module can be independently build, tested, and debugged.
  4. 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.
  5. Also Android app module and Library module are different.
  6. You can keep two different versions of module based on the API releases as from ASOP.

You can have a look for more on android developer resource

How modularization can speed up your Android app’s built time

App modularization and module lazy loading at Instagram and beyond

Modularizing Android Applications by Mauin

Survey on how Android developers were modularising their apps

like image 73
Anurag Singh Avatar answered Sep 17 '22 17:09

Anurag Singh


There was an article on Medium yesterday, which exactly adresses my question:

https://medium.com/@nikita.kozlov/how-modularisation-affects-build-time-of-an-android-application-43a984ce9968#.at4n9imbe

tl;dr:

First and most important, the hypothesis was correct, modularising project can significantly speed up build process, but not for all configurations.

Second, if splitting is done in a wrong way, then build time will be drastically increased, because Gradle build both, release and debug version of library modules.

Third, working in test-driven way is much easier for a project with multiple modules, because building a small library module is way faster then the whole project.

Forth, doing many things in parallel slows down the build. So having more powerful hardware is a good idea.

Below you can find results of all experiments described in this article

Update

Addressed at Google I/O '17: https://youtu.be/Hx_rwS1NTiI?t=23m17s

like image 34
Tobias Avatar answered Sep 16 '22 17:09

Tobias