Search code examples
androidgradlegradle-kotlin-dsl

How to define a BuildConfig field for all modules of a project (gradle KTS)?


Is there any way I can create a BuildConfig field for all my modules through the project's build.gradle.kts file?


Solution

  • Finally. I just found a way on how to do that.

    // build.gradle.kts (of the project)
    
    subprojects {
        afterEvaluate {
            (extensions.findByName("android") as? BaseExtension)?.apply {
                defaultConfig {
                    buildConfigField("String", "base_url", "\"my.base.url\"")
                }
            }
        }
    }