Nowadays, many applications require channel packs and vest packs, and different channel packs or vest packs may have some differences in functions, such as logo, app name and signature. So how do we solve this

Playing channel first want to learn the official Google flavor document, this is the address developer.android.com/studio/buil…

And then we’re going to do it

Step 1: Create the productFlavor in your app build.gradle module.

This creates two channels, and we can define different package names for each channel

In this way, we can choose different channels and play different channel packages

Below we set different logos and app names for different channels

First we create an XML file under SRC, as shown in the figure above

As you can see, we can create resource files under different channel folders, and when we compile the corresponding channel folder, we will take resources from the corresponding channel folder first

If it is not in the channel folder, we will look for it in main. In the corresponding channel folder, we can define the XML, put the image, and the code, and compile from this folder first, if not, we will get the default from main

All resources and code classes we define in the channel folder must have a default file in main, otherwise we will compile an error

In this way, we have created folders for different channels, the main functions are written in main, and the different functions of different channels are covered by the minimum granularity of classes or resources in the corresponding channel folder (main must have default classes or resources).

Different channel packages, using different signatures

If the function is different, you can use the method of class overwriting, or you can judge by the package name

ProductFlavor can only be defined in app modules. If other modules have different functions and need a Flavor, you can add the productFlavor. If a module has a productFlavor, all other modules that reference it need to add the productFlavor