Skip to content Skip to sidebar Skip to footer

While Using Product Flavours What Files Are Common In Each Flavour And What Files Are Specific To That Flavour?

productFlavors { India { } USA { } } Lets take 2 product flavours for an example 1. India 2. USA total number of build variants will be 4 1

Solution 1:

Product Flavour is a awesome solution to build different varieties of the same application with individual features.

Specific Files

Say like , one of your Activity will have different functionality and UI, then you can avoid keeping that Activity in common package and move to respective flavour. Each flavour can have separate java and res folder along with Manifest (which is not mandatory, Studio take care of itself). It is here your specific Activity's java file and xml file should be placed.

Example : Login Screen will have different UI and features in each flavour

Now during runtime as well as compile time, Android Studio switches between the packages and picks suitable files. This is done through Build Variant feature

enter image description here

Common Files

So coming to common files which is applicable is all the flavours, let it be in main/java and main/res itself.

Ideally depending on your flavour numbers, bundle.gradle will look similar to this.

productFlavors {

        student {
            applicationId "com.abc.student"
        }
        staff {
            applicationId "com.abc.staff"
        }
        tempstaff {
            applicationId "com.abc.tempstaff"
        }
    }
sourceSets {
        tempstaff {
            manifest.srcFile 'src/tempstaff/AndroidManifest.xml'
        }
        student{
            manifest.srcFile 'src/student/AndroidManifest.xml'
        }
        staff {
            manifest.srcFile 'src/staff/AndroidManifest.xml'
        }
    }

Now to conclude the answer, files which are common throughout the application will remain in the main package. Specific files applicable to separate flavour will go in that flavour. This means flavours can have extra Activity/Features that are not at all a part of others including main also

Go through this link for more information.

Post a Comment for "While Using Product Flavours What Files Are Common In Each Flavour And What Files Are Specific To That Flavour?"