如何在Android Studio中使用口味

问题描述 投票:0回答:1

在我的应用程序中,我想在我的应用程序中使用调味料。我将以下代码添加到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

我该如何解决?

android android-studio android-studio-3.0
1个回答
1
投票

您必须选择构建变体以运行各自的样式。要找到构建变体选项卡,请看下面的屏幕截图。

enter image description here


0
投票

如果要使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始终设置为默认值,无论您先前选择了哪种构建变体。

© www.soinside.com 2019 - 2024. All rights reserved.