This message was deleted.
# android
s
This message was deleted.
e
how do you intend to use those build config fields from source code? if they aren't defined in the prod variant, you can't compile code that references them in prod.
r
Yes, you can have specific build config values in specific variants. But then you need to make sure you have different source sets using them. Because as ephemient mentions, you won’t be able to build a variant that has any reference to a build config non existing in that configuration. You will need to write your code classes in the specific folders for each variant. So, if you have this:
Copy code
defaultConfig {
	buildConfigField('int', 'COMMON', '999')
}

release {
    buildConfigField('int', 'API_KEY', '123')
    buildConfigField('int', 'ONLY_RELEASE', '222')
}

debug {
    buildConfigField('int', 'API_KEY', '456')
    buildConfigField('int', 'ONLY_DEBUG', '111')
    buildConfigField('int', 'ANOTHER_DEBUG', '333')
}
Then in your code, the build config values you can use:
src/main/
--> must be defined in all variants (API_KEY, COMMON)
src/release/
--> only those defined for prod variant (COMMON, API_KEY, ONLY_RELEASE)
src/debug/
--> only those defined for debug variant (COMMON, API_KEY, ONLY_DEBUG, ANOTHER_DEBUG)
c
Ah perfect. exactly what i needed and easier than I though. Cheers!