I have an Android project which is architectured in a Modularized way. I have modularized the projects by dividing their source code between multiple Gradle modules, following the clean Architecture.
Here is the structure of the App.
The top module in this hierarchy, App
is the one that no other module depends upon, is the main module of your application. The lower level modules domain
and data
do not depend on the App
module, where the App
module includes the data
and domain
modules. I have added the below code in the build.gradle of the app
module
implementation project(':domain')
api project(':data')
Now, I'm having some issues with maintaining dependencies across each module. Since each of them is an individual android module, each of them having its own build.gradle
. The App
module can use classes in the data
and domain
modules. But, I have some general purpose classes, (Such as some annotations, Utilities, Broadcast classes, Dagger scopes etc) which I want to make use in all the modules. But these are the issues I'm facing
- Since these classes are contained in the main module
app
, I cannot access these in mydata
anddomain
, because those modules do not depend on the higher layerapp
- Any libraries I'm using in all the layers (eg: RxJava) needs to be included in the
build.gradle
of each module
As a solution for this I thought of adding one more android module, say common
which will be containing all my general purpose classes as well as the libraries which I use in all the modules.
All my other modules app
, domain
and data
will be having this module as a dependency.
implementation project(':common')
So, any global libraries and classes will be added to this module and each of the individual modules will have only module-specific classes.
Is that a good approach? Or is there any way to solve this issue efficiently?