[英]How to manage configuration based on build type and build flavor
In my app I have 2 build types release
and debug
, below is the code snippet.在我的应用程序中,我有 2 种构建类型
release
和debug
,下面是代码片段。
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.我还有 2 种产品口味,下面是代码片段。
flavorDimensions("version")
productFlavors {
create("flavor1") {
setDimension("version")
}
create("flavor2") {
setDimension("version")
versionCode = 1
versionName = "1.0"
}
}
Now in total I have 4 product types现在我总共有 4 种产品类型
Now I need to create a variable app_name so that the app name can be different for different product types.现在我需要创建一个变量 app_name 以便不同产品类型的应用程序名称可以不同。
How do I achieve the same using configuration or strings.xml我如何使用配置或 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?编辑:让我们假设,我正在使用第三方库并且我想使用不同的身份验证密钥,我如何使用
Flavor
和buildType
组合来实现这一点?
ie I need 4 different keys based on following configuration即我需要基于以下配置的 4 个不同的键
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"
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.