所有产品口味都可以组合到一个版本中

时间:2019-05-19 08:51:40

标签: android build

在我的项目中,我创建了产品风味:bluegreenred。但是当我查看构建变体时,它显示了blueRedGreenDebugblueRedGreenRelease。正如您在下面的图片中看到的。

产品香精 enter image description here

构建变体 enter image description here

3 个答案:

答案 0 :(得分:1)

如您所见here,您必须定义flavorDimensions。

android {
    ...
    defaultConfig {...}
    buildTypes {
        debug{...}
        release{...}
    }
    // Specifies one flavor dimension.
    flavorDimensions "version"
    productFlavors {
        demo {
            // Assigns this product flavor to the "version" flavor dimension.
            // This property is optional if you are using only one dimension.
            dimension "version"
        }
        full {
            dimension "version"
        }
    }
}

答案 1 :(得分:1)

尝试此操作一定会对您有所帮助。

flavorDimensions "paid", "free", "other"

productFlavors {

            blue {
                targetSdkVersion 27
                versionCode 1
                versionName "1.0"
                versionNameSuffix 'blue'
                dimension "paid"
                applicationId "com.itroom.productFlavors.blue"
            }
            green {
                minSdkVersion 15
                targetSdkVersion 26
                versionCode 1
                versionName "1.0"
                dimension "other"
                applicationId "com.itroom.productFlavors.green"
            }
            red {
                targetSdkVersion 27
                versionCode 1
                versionName "1.0"
                versionNameSuffix 'red'
                dimension "free"
                applicationId "com.itroom.productFlavors.red"
            }

        }

替换为

flavorDimensions "default"

productFlavors {

        blue {
            targetSdkVersion 27
            versionCode 1
            versionName "1.0"
            versionNameSuffix 'blue'
            applicationId "com.itroom.productFlavors.blue"
        }
        green {
            minSdkVersion 15
            targetSdkVersion 26
            versionCode 1
            versionName "1.0"
            applicationId "com.itroom.productFlavors.green"
        }
        red {
            targetSdkVersion 27
            versionCode 1
            versionName "1.0"
            versionNameSuffix 'red'
            applicationId "com.itroom.productFlavors.red"
        }

    }

答案 2 :(得分:0)

            flavorDimensions "default"

                productFlavors {

                    APP1{
                        applicationId "com.project.androidone"
                        versionCode 1
                        versionName "1.0"
                        flavorDimensions "other"
                        signingConfig signingConfigs.businessConfig

    setProperty("archivesBaseName","PROJECT_V1_$versionName.$versionCode")
                        }


                   APP2{
                        applicationId "com.project.androidtwo"
                        versionCode 1
                        versionName "1.0"
                        flavorDimensions "paid"
                        signingConfig signingConfigs.businessConfig

    setProperty("archivesBaseName","PROJECT_V1_$versionName.$versionCode")
                          }

                   APP3{
                        applicationId "com.project.androidthree"
                        versionCode 1
                        versionName "1.0"
                        flavorDimensions "free"
                        signingConfig signingConfigs.businessConfig

    setProperty("archivesBaseName","PROJECT_V1_$versionName.$versionCode")
                        }
                }