I have two Android projects. Code that can be shared between these two projects has been put in a separate project that is included in each Android project as a sub module.
I recently tried to define my dependencies using extra properties extensions and had success doing this in the two root projects. Here is an overview of what I did.
- Defined an ext object in a
dependencies.gradle
file at the root of the project. - Applied this file from within the root
build.gradle
apply from: 'dependencies.gradle'
- Used the properties I defined within the root project’s only module, e.g
def appDependencies = rootProject.ext.appDependencies
implementation appDependencies.androidSupportAppCompat
// more dependencies
However, I was unable to replicate the same in the sub module project. The sub module project also has its dependencies and should thus define its own dependencies.gradle file. I applied the dependencies.gradle
file and tried to get the properties defined therein using rootProject.ext.appDependencies
.
rootProject.ext.appDependencies
reads the extra properties extension from the root project even when called from within the sub module’s build.gradle
file. I thus have errors like these.
Cannot get property 'commonDependencies' on extra properties extension as it does not exist
This behavior seems logical to me. How do I read the extra properties extensions defined in the sub module from the sub module’s gradle file?