Last active
December 21, 2023 05:40
-
-
Save victory316/aa07a2947e2e60ac052cf34d5bdec2ba to your computer and use it in GitHub Desktop.
Setup BuildConfig in different build flavour when using up to gradle 8.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildTypes { | |
release { | |
isDebuggable = false | |
isMinifyEnabled = true | |
proguardFiles( | |
getDefaultProguardFile("proguard-android-optimize.txt"), | |
"proguard-rules.pro" | |
) | |
configure<CrashlyticsExtension> { | |
mappingFileUploadEnabled = true | |
} | |
buildConfigField("String", "API_BASE_URL", "\"https://my.real.server\"") | |
} | |
debug { | |
signingConfig = signingConfigs.getByName("debug") | |
isDebuggable = true | |
buildConfigField("String", "API_BASE_URL", "\"https://my.dev.server\"") | |
} | |
} | |
flavorDimensions += listOf("environment") | |
productFlavors { | |
create("dev") { | |
resValue("string", "app_name", "Alpha DEV") | |
dimension = "environment" | |
applicationIdSuffix = ".dev" | |
} | |
create("prod") { | |
dimension = "environment" | |
applicationIdSuffix = "" | |
} | |
} | |
buildFeatures { | |
buildConfig = true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Must setup same flavor with application module. Also should set on every modules related each other. | |
buildTypes { | |
release { | |
isDebuggable = false | |
isMinifyEnabled = true | |
proguardFiles( | |
getDefaultProguardFile("proguard-android-optimize.txt"), | |
"proguard-rules.pro" | |
) | |
configure<CrashlyticsExtension> { | |
mappingFileUploadEnabled = true | |
} | |
buildConfigField("String", "API_BASE_URL", "\"https://my.real.server\"") | |
} | |
debug { | |
signingConfig = signingConfigs.getByName("debug") | |
isDebuggable = true | |
buildConfigField("String", "API_BASE_URL", "\"https://my.dev.server\"") | |
} | |
} | |
flavorDimensions += listOf("environment") | |
productFlavors { | |
create("dev") { | |
dimension = "environment" | |
buildConfigField("String", "API_BASE_URL", "\"https://my.dev.server\"") | |
} | |
create("prod") { | |
dimension = "environment" | |
buildConfigField("String", "API_BASE_URL", "\"https://my.real.server\"") | |
} | |
} | |
productFlavors.forEach { | |
if (it.name.contains("dev")) { | |
it.buildConfigField("String", "API_BASE_URL", "\"https://my.dev.server\"") | |
} else if (it.name.contains("prod")) { | |
it.buildConfigField("String", "API_BASE_URL", "\"https://my.real.server\"") | |
} | |
} | |
buildFeatures { | |
buildConfig = true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment