DEV Community

Carlos Okumu
Carlos Okumu

Posted on

Splitting a monolithic Android Application

Image description

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'
Enter fullscreen mode Exit fullscreen mode

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.

Image description
Core modules that contain android framework references will need to use the library plugin:

apply plugin: 'com.android.library'
Enter fullscreen mode Exit fullscreen mode

If they do not reference the android framework,then use pure kotlin or java modules

apply plugin: 'kotlin'
Enter fullscreen mode Exit fullscreen mode

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 πŸ™‚

Latest comments (0)