Another Navigation in Android Multi Module Architecture
At Jibble, we moved to a multi module architecture. Alongside with that, we have Kotlin Multiplatform that powers our core business logic and gives us a shared code between Android and iOS. It’s a monorepo project and we only use Kotlin Native for pure business logic code. Everything else related with iOS and Android is being handled on native side. The project is mainly a MVVM architecture. But we have extra couple of layers. Main components are:
- View → Activity or Fragment
- ViewModel → Communicator between Interactor and the View
- Interactor → Kotlin Native shared logic.
- Assembler → Assembles View, ViewModel, Interactor and Route.
- Route → Not the Router ❌
This can be another post topic but in short, the main benefit of this architecture for us is to avoid logical differences between platforms and reduce the amount of time to write Unit Tests for each platform. Cause we write tests for our core business logic only once, which are Interactors.
I will show a small example of how we use navigation in our multi module application. This example will be a shortened version of our actual navigation architecture without showing all the details about Assembler and Interactor. But rather it will focus on navigating from a
Main App Module to
Feature A Module and then navigation from
Feature A Module to another
Feature B Module.
You might ask, what’s the issue in here? Well,
app module depends on
featureModuleB. Thus, it can easily start
FeatureScreenBActivity. But what if we need to start
FeatureScreenAActivity and vice versa. They don’t know about each other. And if we give dependency to each other, then we create a circular dependency graph which won’t work.
One way to achieve calling non-dependent activities is via defining the class package name on Intent creation.
val intent = Intent()
Actually you can find a good article about this approach on this link from Gaël Marhic…