Is there a way to have a common section with buildConfigField and resValue in gradle?

Selvin is correct, use the defaultConfig closure – there is no neater way! In the following example, flavors 1, 2 & 5 would set the default country and language to de. Flavors 3 & 4 override this with their own languages.

defaultConfig {
    buildConfigField "String", "country", "de"
    buildConfigField "String", "language", "de"
}

buildTypes {
    debug {
    }

    release {
    }
}

productFlavors {
    flavor1 {
        buildConfigField "String", "appName", "Flavor1"
    }
    flavor2 {
        buildConfigField "String", "appName", "Flavor2"
    }
    flavor3 {
        buildConfigField "String", "country", "uk"
        buildConfigField "String", "language", "en_GB"
        buildConfigField "String", "appName", "Flavor3"
    }
    flavor4 {
        buildConfigField "String", "country", "fr"
        buildConfigField "String", "language", "fr"
        buildConfigField "String", "appName", "Flavor4"
    }
    flavor5 {
        buildConfigField "String", "appName", name.capitalize()
    }
}

NOTE

Just an FYI that you can use name.capitalize() to turn the name of any flavour, e.g. flavor5, into the app name of Flavor5 by using the capitalize() method – which will capitalize the first character in the String. However, this MUST go in the flavor, not defaultConfig

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)