Does Android Studio support sub-flavors?

痞子三分冷 提交于 2020-01-13 17:10:35

问题


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

Both flavors have some common code under src/main

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

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?


回答1:


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


来源:https://stackoverflow.com/questions/39088271/does-android-studio-support-sub-flavors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!