Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Android Studio support sub-flavors?

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?

like image 926
sam Avatar asked Aug 22 '16 20:08

sam


People also ask

What are Flavours in Android Studio?

Android Product Flavors are used to create different app versions. App versions can be free or paid. They can have different themes and texts. They can use different environments or APIs.

What is Gradle flavor?

To do this, the Android plugin for Gradle allows you to create multiple groups of product flavors as flavor dimensions. When building your app, Gradle combines a product flavor configuration from each flavor dimension you define, along with a build type configuration, to create the final build variant.

What does minifyEnabled do?

So minifyEnabled removes dead code but does not obfuscate or optimize.


1 Answers

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"
    }
like image 88
peter.bartos Avatar answered Sep 30 '22 12:09

peter.bartos