What I have
I have two different modules in my android project:
- app: This is the main app android module, where is located almost all the code of the app.
- core: This is another module where I would like to specify all the base code that will be used in the app module, like BaseFragment, BaseViewModel, or interfaces that I would like to implement in the app module.
In the core build.gradle file, I have all of these dependencies:
//Moshi
implementation "com.squareup.moshi:moshi-kotlin:$moshi_version"
//Retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-moshi:$moshi_converter_version"
//okhttp
implementation "com.squareup.okhttp3:okhttp:$okhttp3_version"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_loggin_interceptor"
//Koin
implementation "io.insert-koin:koin-android:$koin_version"
implementation "io.insert-koin:koin-androidx-viewmodel:$koin_viewmodel_version"
All of these dependencies I would like not to be declared also in the app build.gradle file.
I am reading some blogs and the Gradle official documentation but I am not able to successfully achieve this.
What I want
I want to "inherit" all the dependencies just from the core module gradle file
The structure of the project should be something like this:
core
|_build.gradle (common dependencies)
|_app
|_build.gradle (just specific dependencies)
What I have tried
I have read that this is possible implementing the core project as follows (in the app build.gradle file):
dependencies {
implementation project (":core")
......
}
But I have some classes in the app module that uses core classes` that could not find. For example:
import com.example.core.presentation.base.BaseViewModel
The error says that could not resolve the reference like it not exists.
Some ideas?
Thanks in advance!!