0

Is there an easy way to include common flavor settings in a flavor when the flavors are split out by build settings?

Take the below example. I'd like to have all the settings in the flavor1 group below included in both the Debug and Release flavors. This is obviously a simplified example, as I have 4 flavors and over 20 settings common between them and I don't wan to duplicate them.

android {
    productFlavors {
        flavor1Debug {
            resValue 'string', 'application_name', 'DebugName'
        }
        flavor1Release {
            resValue 'string', 'application_name', 'RelaseName'
        }

        //flavor1 {
        //    buildConfigField 'String', 'DEFAULT_LANGUAGE_CODE', '"en"'
        //}
    }
}
Gary Bak
  • 4,746
  • 4
  • 22
  • 39
  • Yes, everything is described here [is here](https://stackoverflow.com/questions/17197636/is-it-possible-to-declare-a-variable-in-gradle-usable-in-java) :) – Andree6969 Nov 08 '18 at 17:55

1 Answers1

0

There is a defaultConfig section, you can provide the base configuration for all flavors in the defaultConfig block, and each flavor can change any of these default values. for example:

android {
    defaultConfig {
        manifestPlaceholders = [hostName:"www.example.com"]
        ...
    }
    buildTypes {
      debug{...}
      release{...}
    }

   flavorDimensions "version"
   productFlavors {
     demo {
        dimension "version"
        manifestPlaceholders = [hostName:"www.otherexample.com"]//this flavor change manifestPlaceholders 
        ...
     }
     full {
        dimension "version" //this flavor extends manifestPlaceholders from `defaultConfig`
        ...
     }
   }
navylover
  • 12,383
  • 5
  • 28
  • 41