You can learn how to create multi module Android project with this repository.

Overview

MultiModuleProjectSample

You can learn how to create multi module Android project with this repository. You can read this article in Turkish. Go to this link.

Greetings, with this article, we will learn about the benefits of a multi-module project and how we can create a multi-module project.
Before I start, I need to mention the following: As you know, many methods can be used when performing such operations. As I progress, I will use one of these methods and we will proceed with the Kotlin programming language in the Android Studio environment. Let's get started :)

start-image

Image 1 Photo by Ryoji Iwata[1]

Benefits of the Modular Project

One of the main controversial topics of Android development is Modularization. In the past, it was not strange at all that our project only had one application module. We need to concentrate on the layers of our application, separate them and follow some principles of some famous architectures. But these days, when we have a large team working on a monolithic project that is facing a lot of issues like compile time, code conflicts, and running our app per change, maintaining projects gets out of hand. We may be disappointed while developing and executing our project.

There are many reasons to Modularize the Project:

  • Build Time: The long Compile and Build times of our project.
  • Reusability: Our sharing of some Features between multiple applications.
  • Maintenance: Huge, spaghetti codebase where each Feature has many side effects on the other.
  • Test: You can’t write a simple test scenario for a self-contained Feature.
  • App Size: Contrary to a monolithic application size, in a modular application, we can achieve smaller size installation files thanks to Bundle and Dynamic Features.
  • Demo Apps: Reasons like running the whole project for a small change and running a single Feature isolated from the whole application lead us to modular builds.

start-image

Image 2 Photo by Ryan Quintal[2]

Creating the Project

In the project we will create, there will be app, buildSrc, data and domain modules. To briefly mention them;

  • app: Application module. It contains all the initialization logic for the Android environment.
  • buildSrc: In this module, we keep the whole version system to be used in the application.
  • domain: It is the module that contains the most important part of the application, the business logic. This module depends solely on itself and all the interactions it does are through dependency reversal.
  • data: It is the module that contains the data (local, remote, etc.) in the application.

After this brief briefing, let's first create a normal project. The monolithic (single-module) Android project looks like this.

image

Default Project View

Now let's look at how a module can be added. Let's take the first step by adding a Kotlin module called buildSrc to manage libraries more easily :)

For this, we can click on File -> New -> New Module. These clicks take us to a screen like the one below.

image

Create the buildSrc module

Our buildSrc module will not be an Android related process, for this we can build the module via Java or Kotlin library.

Note: If you get an error like "'buildSrc' cannot be used as a project name as it is a reserved name", go to settings.gradle and delete the "include ':buildSrc'" code here and try to build again.

After adding the buildSrc module, you can activate the Kotlin DSL by renaming the build.gradle file of the relevant module to build.gradle.kts. Also you can make the content as follows.

image

build.gradle.kts

After doing all this, we will finally create a Versions Kotlin file for buildSrc where we can keep the relevant versions. Here we will hold values to define the versions we will use within the application. So, we will be able to easily do version control from one place. You can see the latest version of the "buildSrc" module and the Versions Kotlin file in the image below.


image

buildSrc module and Versions Kotlin file

Now let's add the "data" module. As when adding the "buildSrc" module, we will proceed as File -> New -> New Module and add the module as follows.

image

Create the data module

You can see the latest version of the "data" module below. You can fill the contents of the package as you wish.

image

Latest version of data module

Now that we have created the data module, let's create the domain module. Again, let's go to File -> New -> New Module.

image

Create the domain module

This way we can create the "domain" module. The reason why we move to Android here is shaped according to our needs. For example, if we needed a manifest file in this module, we could create our module via the Android Library option.

image

Adding the domain module to the project

This is how we added the "domain" module to the project.

Above, we had a discourse about the speed of module projects. There are some actions we can take when accelerating a modular project. It is possible to get a build much faster by adding the following codes to our "gradle.properties" file.

org.gradle.jvmargs=-Xmx2048m -XX:+UseParallelGC
org.gradle.daemon=true
org.gradle.caching=true
org.gradle.parallel=true

For more detailed information about these codes, you can take a look at my article titled "Android Projelerde Build Sürelerini Hızlandırma".

Abstract

In this article, we talked about the importance of modularity in our Android applications and how we can create a modular project. You can manage your project better by creating different modules according to your needs.

References:

  1. https://unsplash.com/@ryoji__iwata?utm_source=medium&utm_medium=referral
  2. https://unsplash.com/@ryanquintal?utm_source=medium&utm_medium=referral
  3. https://www.droidcon.com/2022/02/15/android-modularization-preps-things-to-know-before-modularizing-your-app/

License

MIT License

Copyright (c) 2022 Adem ATİCİ

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You might also like...
This repository is a playground of jetpack compose for android developers
This repository is a playground of jetpack compose for android developers

Pritesh Jetpack Compose This repository is a playground of jetpack compose for Android Developers, I tried to get my hands dirty with challenging UI t

Lull is an Android mobile application made with Jetpack Compose, where you can download wallpapers.
Lull is an Android mobile application made with Jetpack Compose, where you can download wallpapers.

Lull Lull is an Android mobile application made with Jetpack Compose, where you can download wallpapers. Table of Contents Features Screenshots Light

Jetpack Compose android app that you can send push notification among devices using KTOR and One Signal
Jetpack Compose android app that you can send push notification among devices using KTOR and One Signal

Jetpack Compose android app that you can send push notification among devices using KTOR and One Signal, Clean Architecture, Dependency Injection...

 神奇宝贝 (PokemonGo) 基于 Jetpack + MVVM + Repository + Paging3 + Kotlin Flow 的实战项目
神奇宝贝 (PokemonGo) 基于 Jetpack + MVVM + Repository + Paging3 + Kotlin Flow 的实战项目

这是一个小型的 App 项目,涉及到技术:Paging3(network + db),Dagger-Hilt,App Startup,DataBinding,Room,Motionlayout,Kotlin Flow,Coil,JProgressView 等等。

Here you can try out Kotlin Multiplatform and Jetpack Compose with some other cutting-edge technologies.
Here you can try out Kotlin Multiplatform and Jetpack Compose with some other cutting-edge technologies.

wire The Wire is a Kotlin Multiplatform sample project, currently supporting Android and Windows. Tools And Technolagies Architecture: MVVM MultiThrea

A library that you can use in 4 different types toast written with Jetpack Compose
A library that you can use in 4 different types toast written with Jetpack Compose

Composable Sweet Toast A library that you can use in 4 different types(Success, Error, Warning, Info) written with Jetpack Compose. You can use this t

A library that you can use in 4 different types(Success, Error, Warning, Info) written with Jetpack Compose.
A library that you can use in 4 different types(Success, Error, Warning, Info) written with Jetpack Compose.

Composable Sweet Toast A library that you can use in 4 different types(Success, Error, Warning, Info) written with Jetpack Compose. You can use this t

Examples of ParallaxView and ParallaxScrollEfect are in the repo. You can find the necessary titles and outputs in the continuation of the Readme file. 🪞
Examples of ParallaxView and ParallaxScrollEfect are in the repo. You can find the necessary titles and outputs in the continuation of the Readme file. 🪞

Parallax Examples : Examples of ParallaxView and ParallaxScrollEfect are in the repo. You can find the necessary titles and outputs in the continuatio

Simple example how you can use dynamic color image vector in your app.
Simple example how you can use dynamic color image vector in your app.

Dynamic Color ImageVector Simple example how you can use dynamic color image vector in your app. How to use 1. Create a xml image vector The content o

Owner
Adem ATİCİ
Software Engineer - Android Developer
Adem ATİCİ
Android App made by Jetpack Compose Components with Kotlin, MVVM Pattern, Multi Module, Navigation, Hilt, Coroutines, Retrofit and cached data by Room

Android App made by Jetpack Compose Components with Kotlin, MVVM Pattern, Multi Module, Navigation, Hilt, Coroutines, Retrofit and cached data by Room

Yogi Dewansyah 13 Aug 31, 2022
Android App made by Jetpack Compose Components with Kotlin, MVVM Pattern, Multi Module, Navigation, Hilt, Coroutines, Retrofit and cached data by Room

Mobile Banking Android App made by Jetpack Compose Components with Kotlin, MVVM Pattern, Multi Module, Navigation, Hilt, Coroutines, Retrofit and cach

Yogi Dewansyah 13 Aug 31, 2022
A Clean Architecture App to show use of multi module architecture in a Jetpack Compose

Nextflix-Composable A Clean Architecture App to show use of multi-module-archite

Talha Fakıoğlu 196 Dec 19, 2022
An app for Android that uses quizzes to help you learn more about computer science.

Quiz App An app for Android that uses quizzes to help you learn more about computer science. ?? Screenshots No screenshot available yet ?? Tech Stack

Ivan Ramos 2 Nov 8, 2022
A collection of animations, compositions, UIs using Jetpack Compose. You can say Jetpack Compose cookbook or play-ground if you want!

Why Not Compose! A collection of animations, compositions, UIs using Jetpack Compose. You can say Jetpack Compose cookbook or play-ground if you want!

Md. Mahmudul Hasan Shohag 186 Jan 1, 2023
A sample project in Kotlin to demonstrate Jetpack Compose, MVVM, Coroutines, Hilt, Room, Coil, Retrofit, Moshi, Leak Canary and Repository pattern

Jetpack-Compose-Boilerplate This repository contains a sample project in Kotlin to demonstrate Jetpack Compose, MVVM, Coroutines, Hilt, Room, Coil, Re

Areg Petrosyan 14 Dec 12, 2022
Let's learn the basics of Jetpack Compose

MyPlaygroundForJetpackCompose Let's learn the basics of Jetpack Compose Info This project is a self learning project for me. The goal of the project i

Emre Tekin 1 Jan 8, 2022
Google CodeLab: learn how to use some Animation APIs in Jetpack Compose.

Compose Animation Codelab This folder contains the source code for the Compose Animation codelab. In this codelab, you will learn how to use some Anim

Ryan Wong 0 Dec 26, 2021
Stock Ticker / Watchlist App being used as an excuse to learn Compose and other Jetpack libs.

StockTicker App Simple app that displays a few FAANG stock tickers and allows the user to search for and add different tickers to a watchlist. API Key

Alex Hart 2 Aug 26, 2022
android multi-fab that made with jetpack-compose

ComposeMultiFab android multi-fab that made with jetpack-compose Download implementation "io.github.jisungbin:multifab:${version}" Usage @Composable f

Ji Sungbin 8 Dec 3, 2022