Android Studio是否支持子口味? [英] Does Android Studio support sub-flavors?

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

问题描述

我有一个Android Studio项目,当前在build.gradle中具有以下两种产品风格:

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"
            }
        }
    }

所以我的目标是拥有两种类型的应用程序(教师和父级),每种类型都可以自定义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)

任何想法如何实现?

推荐答案

是的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是否支持子口味?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆