![](/img/trans.png)
[英]How combine build type and flavor to get a build variant debug<Flavor>
[英]How to manage configuration based on build type and build flavor
在我的应用程序中,我有 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")
}
}
我还有 2 种产品口味,下面是代码片段。
flavorDimensions("version")
productFlavors {
create("flavor1") {
setDimension("version")
}
create("flavor2") {
setDimension("version")
versionCode = 1
versionName = "1.0"
}
}
现在我总共有 4 种产品类型
现在我需要创建一个变量 app_name 以便不同产品类型的应用程序名称可以不同。
我如何使用配置或 strings.xml 实现相同的目标
编辑:让我们假设,我正在使用第三方库并且我想使用不同的身份验证密钥,我如何使用Flavor
和buildType
组合来实现这一点?
即我需要基于以下配置的 4 个不同的键
任何帮助,将不胜感激。
在每个源集中声明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.