Splitting a monolithic Android Application
Carlos Okumu
Posted on February 12, 2022
Splitting a monolithic application code base into modules is not a new theme.In most cases,a single module will do the job but as the application becomes bigger,we may need to put things into modules and link them up accordingly.Modularization really provides a neat way to split responsibility amongst the different modules.Now let's jump in and see how we can achieve this.
Application Module
We will start here because this is the default module android studio creates when you start a new project
This is essentially the main module of your application and will often be under the app module, using the application plugin in the modules build.gradle file to signify this:
apply plugin: 'com.android.application'
Now if you’re building a single module application then this will be the only module-type plugin that you will be using throughout your project. In single module projects, this base module will contain all of your applications responsibilities — be in User Interface, Networking, Cache, Data operations — you name it and it will be there.
Core Modules
You can essentially use these modules to separate out related areas of your project so that they are decoupled from the main module of your project.
For example if your application has a complex data layer that communicates with both a remote and cache data source.You will need to separate responsibilities as shown in the image below.
Core modules that contain android framework references will need to use the library plugin:
apply plugin: 'com.android.library'
If they do not reference the android framework,then use pure kotlin or java modules
apply plugin: 'kotlin'
Thanks for reading through,this was just a basic overview of how modularization can be a achieved in android projects.Be sure to check out my future writings.Follow me on github here.Happy Coding 🙂
Posted on February 12, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024