本文介绍了Android Studio 是否支持子口味?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Android Studio 项目,目前在 build.gradle 中有 2 种产品风格,如下所示:

I have an Android Studio project that currently has 2 product flavors in the build.gradle as follows:

productFlavors {
        parent {
            applicationId "xxx.parent"

        }
        teacher {
            applicationId "xxx.teacher"
        }
    }

两种风格在 src/main 下都有一些共同的代码

Both flavors have some common code under src/main

我需要的是 1 级以上的风格,所以我希望在一种风格下有子风格,这是 1 级以上的自定义(对于某些资源和一些静态变量)

What I need is 1 more level of flavors, so I want under one flavor to have sub flavors which is 1 more level of customization (for some resources & some static variables)

所以我想要类似于下面的内容:

So I want something similar to below:

productFlavors {
        parent {
            p1 {
                applicationId "xxx.parent.p1"
               }
            p2 {
                applicationId "xxx.parent.p2"
               }
        }
        teacher {
            t1 {
                applicationId "xxx.teacher.t1"
            }
            t2 {
                applicationId "xxx.teacher.t2"
            }
        }
    }

所以我的目标是有 2 种类型的应用程序(老师和家长),每个都可以自定义 n 次(它们会因应用程序 ID、资源文件和静态变量而异)

So my aim is to have 2 types of applications (teacher & parent) and each can be customized n times (they will differ by application id, resource files & static variables)

知道如何实现这一目标吗?

Any idea how can this be achieved?

推荐答案

是 Gradle 支持子风格 - flavorDimensions.例如:

Yes Gradle supports sub flavors - flavorDimensions. E.g.:

flavorDimensions "server", "lib"

productFlavors {
    pub {
        dimension "server"
        minSdkVersion 19
        resValue "string", "app_version_name", mVersionName
    }
    beta {
        dimension "server"
        minSdkVersion 9
        resValue "string", "app_version_name", mVersionName + "beta"
    }
    xwalk {
        dimension "lib"
    }
    webkit {
        dimension "lib"
    }

这篇关于Android Studio 是否支持子口味?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 05:40