You can do this with flavors.
In the library module's build.gradle, define a flavor dimension that corresponds to the variable's value:
android {
/* ... */
flavorDimensions "someVar"
productFlavors {
someVarTrue {
dimension "someVar"
buildConfigField "boolean", "SOME_VARIABLE_FROM_APP_MODULE", 'true'
}
someVarFalse {
dimension "someVar"
buildConfigField "boolean", "SOME_VARIABLE_FROM_APP_MODULE", 'false'
}
}
}
In the app module's build.gradle, define which app flavor should use which library flavor:
android {
/* ... */
flavorDimensions "environment"
productFlavors {
prod {
dimension "environment"
}
dev {
dimension "environment"
} // note: naming a flavor "debug" might create a conflict with the default "debug" configuration
}
}
dependencies {
/* ... */
prodImplementation project(path: ':libApp', configuration: 'someVarTrue')
devImplementation project(path: ':libApp', configuration: 'someVarFalse')
}
You might want to see this article for some more details.