In my app I have 2 build types release
and debug
, below is the code snippet.
buildTypes {
getByName("debug") {
applicationIdSuffix = ".debug"
versionNameSuffix = ".debug"
buildConfigField("boolean", "DEBUG_MODE", "true")
}
getByName("release") {
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
buildConfigField("boolean", "DEBUG_MODE", "false")
}
}
and I also have 2 product flavors below is the code snippet.
flavorDimensions("version")
productFlavors {
create("flavor1") {
setDimension("version")
}
create("flavor2") {
setDimension("version")
versionCode = 1
versionName = "1.0"
}
}
Now in total I have 4 product types
Now I need to create a variable app_name so that the app name can be different for different product types.
How do I achieve the same using configuration or strings.xml
Edit: Let's assume, I am using a third party library and I want to use different authentication key, how can I achieve this using Flavor
& buildType
combination?
ie I need 4 different keys based on following configuration
any help would be appreciated.
在每个源集中声明strings.xml,然后你可以为不同的构建类型和风格设置不同的值检查这个
Try this,
productFlavors {
flavorA {
setDimension("version")
manifestPlaceholders = [appLabel : "FlavourA"]
}
flavorB {
setDimension("version")
versionCode = 1
versionName = "1.0"
manifestPlaceholders = [appLabel : "FlavourB"]
}
}
In android manifest file set this appLabel.
<application
android:name=".ApplicationClass"
android:icon="@mipmap/logo_launcher"
android:label="${appLabel}" // Add this line.
android:largeHeap="true"
android:theme="@style/AppTheme"
/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.