Since Kotlin Multiplatform does not natively support Android-style product flavors, you can mimic this behavior by defining a flavor property in gradle.properties and using it to select configurations.
Set a default flavor in gradle.properties:
buildkonfig.flavor=dev
Use the flavor as an argument in defaultConfigs and targetConfigs within your build.gradle(.kts) file.
To override the flavor via CLI (e.g., in CI):
./gradlew build -Pbuildkonfig.flavor=release
Precedence Rules
When multiple configurations define the same field, the following hierarchy determines the winner (strongest to weakest):
Flavored TargetConfig > TargetConfig > Flavored DefaultConfig > DefaultConfig
// Example of flavored configuration in Kotlin DSL
buildkonfig {
packageName = "com.example.app"
defaultConfigs {
buildConfigField(STRING, "name", "base_value")
}
// Flavor-specific default config
defaultConfigs("dev") {
buildConfigField(STRING, "name", "dev_value")
}
targetConfigs("dev") {
create("ios") {
buildConfigField(STRING, "name", "dev_ios_value")
}
}
}