在我的应用程序中,我想在我的应用程序中使用调味料。我将以下代码添加到build.gradle
文件中,但是在设备上运行应用程序时(单击AndroidStudio中的运行按钮)会显示错误的数据!我的口味代码:
defaultConfig {
applicationId "com.app.app"
minSdkVersion 17
targetSdkVersion 29
versionCode 13
versionName "1.0.13"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
//Custom flavors
flavorDimensions "default"
productFlavors {
appFlav2 {
applicationId "com.app.app.myapp2"
resValue "string", "app_name", "App name 2"
resValue "string", "appDescription", "description info 2"
manifestPlaceholders = [
appIcon: "@drawable/logo_niaz"
]
}
appFlav3 {
applicationId "com.app.app.myapp3"
resValue "string", "app_name", "App name 3"
resValue "string", "appDescription", "description info 3"
manifestPlaceholders = [
appIcon: "@drawable/logo_niaz"
]
}
appFlav {
applicationId "com.app.app"
resValue "string", "app_name", "App name"
resValue "string", "appDescription", "description info"
manifestPlaceholders = [
appIcon: "@drawable/launcher"
]
}
}
}
但是在设备上运行应用程序时,显示以下信息:appFlav3。但我的默认风格是appFlav!
我该如何解决?
如果要使isDefault.set(true)
为默认值,则应设置appFlav
:
appFlav {
isDefault.set(true)
applicationId "com.app.app"
resValue "string", "app_name", "App name"
resValue "string", "appDescription", "description info"
manifestPlaceholders = [
appIcon: "@drawable/launcher"
]
}
进行此设置,然后转到Files / Invalidate Caches/Restart
,您将看到appFlav
面板中始终将Build Variants
始终设置为默认值,无论您先前选择了哪种构建变体。