How to pass BuildConfig values to dependency module?

The most easy way is to create a third module(library), and add this module to the dependency of your library module and app module.

Then put the shared build config to the shared third module.

app module <------------------ library module
    ^                                ^
    |                                |
    | dependency                     |dependency
     ------------ third module -------

No, We cant do that. Dependency module can't access the BuildConfig file of App module.

The only alternative solution for your problem is you need add the same properties to your dependency BuildConfig file.


This is how I shared the App Version Code and Version Name with a library/module BuildConfig :

Define version code and name in project level gradle file :

ext {
        appVersionCode = 1
        appVersionName = '1.0.1' 
}

Now in your app gradle :

defaultConfig {
    ....
    versionCode $rootProject.appVersionCode
    versionName $rootProject.appVersionName

And in your library/module gradle :

defaultConfig {
    ....
    def appVersionCode = $rootProject.appVersionCode
    def appVersionName = '\"' + $rootProject.appVersionName +'\"'

    versionCode appVersionCode
    versionName appVersionName

    //This part to get version code and name in library/module BuildConfig file 

    buildConfigField 'int', 'APP_VERSION_CODE', "$appVersionCode"
    buildConfigField 'String', 'APP_VERSION_NAME', appVersionName

A simple project explaining how to share gradle buildConfigField variables with multiple modules : https://github.com/Noddy20/Multi-Module-Gradle-Config