i have declared some build config fields in the ap...
# android
r
i have declared some build config fields in the app module. I am not able to access it in other modules. Do i need to include those fields in every module's gradle file? Or is there some different approach to handle this?
😶 3
i
We used enums to keep track of every flavor we had. That way you can safely declare the same flavors in different modules and keep track of all buildConfig fields. It requires kotlin dsl though
Each module generates its own BuildConfig, so you need to declare the same constant across modules
r
I am using DSL right now. How did you make those enums accessible to other modules? Can you share an example or some resources
i
somehow every module is able to see kotlin files from buildSrc our Config.kt file:
Copy code
enum class Flavors(
        val appName: String,
        val flavorName: String,
        val suffix: String,
        val apiUrl: String,
        val login: String,
        val pass: String,
    ) {
        BANK_DEV(
            "App dev",
            "bankDev",
            ".dev",
            "\"<https://google.com/>\"",
            "\"test2\"",
            "\"2022\"",
        ),
        ;
        companion object {
            const val DIMENSION = "default"
        }
    }
then in app/build.gradle:
Copy code
flavorDimensions(Config.Flavors.DIMENSION)
    productFlavors {
        create(Config.Flavors.BANK_DEV.flavorName) {
            dimension = Config.Flavors.DIMENSION
            applicationIdSuffix = Config.Flavors.BANK_DEV.suffix
            resValue("string", "app_name", Config.Flavors.BANK_DEV.appName)
            buildConfigField("String", "API_URL", Config.Flavors.BANK_DEV.apiUrl)
        }
    }
any other module, for example auth/build.gradle:
Copy code
flavorDimensions(Config.Flavors.DIMENSION)
    productFlavors {
        create(Config.Flavors.BANK_DEV.flavorName) {
            dimension = Config.Flavors.DIMENSION
            buildConfigField("String", "Login", Config.Flavors.BANK_DEV.login)
            buildConfigField("String", "Pass", Config.Flavors.BANK_DEV.pass)
        }
    }
r
If a create a common gradle file and setup these flavors and other configs in that and then for each module if i apply from that common gradle file. It should also work right?
Are you able to get BuildConfig object in your modules other than :app one?
i
Probably yeah, a common gradle file is a good thing too
r
Okay
Thanks for replying 😃
👍 1