AndroidStudio packaging strategy — Gradle-Build Variants to build a customized version of the App

You must have seen such an App, similar to: Doudou Xiaomi special customized version, XXX Meizu first version.
Most of these apps have the same interface style and function implementation as the normal version, but only have some more pendants, such as

  1. Modified the app name, and Dadoudou became the customized version of Dadoudou and Xiaomi
  2. Modified the icon of the App, and added some logos of channel dealers or manufacturers to the startup icon
  3. Modify the start page
  4. Ad-free
    This article focuses on these issues and discusses how to elegantly generate custom apps

Why build with Build Variants

Why use this way to package?
If I get a request like this before, my likely reaction is to checkoutbranch out from the previous stable version, then change the app name, change the startup icon, start page, and remove the advertising logic.
This will of course solve the current problem. But this has several disadvantages

  1. Trouble with code maintenance If you
    checkoutcome out with one code, you will need to maintain two apps and two codes in the future. We may not feel that there are two versions, but this is only one version of customization. If we want to customize the Doudou App in the future, we will not only customize Xiaomi but also customize 360, customize Meizu, and customize Samsung. It is also necessary to distinguish between user groups and launch a version with advertisements and a version without advertisements. Launched a stable version and a Pro version with upgraded features – Super Doudou. How many branches need to be maintained if each version is done with a branch? If the version is upgraded once, does each branch have to be upgraded? How much work is required.

  2. Increased testing burden
    Similarly , for apps that are not implemented based on a set of codes, many repeated tests are inevitably generated during testing.

  3. Inefficient operation of cooperating products
    Because this method causes slow development, troublesome maintenance, and time-consuming testing, resulting in products that cannot keep up with the rhythm and low efficiency.

Main topic – how to create

Generate a customized version of the app name

  1. First of all, how do we change the name of the App without considering Gradle?
    Find the AndroidManifest.xmlfile, applicationthe label in the android:labellabel stores the App name
    See that it is modified through @string/app_namethe files under the values ​​folderstrings.xml
    Seeing this, combined with the knowledge learned in the previous article, we probably already know what to do.
    a. productFlavorsCreate a new channel number insidexiaomi {}
    b. Then create a new directory called in the src directory, which is the same level directory of the main directory xiaomi, then copy values/strings.xml to the directory, and then change the name to the name we want to display.
    Here the app name will be changed

Generate customized icons

With the experience of modifying the name of the app, modifying the icon is easy to do, just the folder where the icon is stored, there will be hdpi、xhdpi、xxhdpiseveral other directories, you need to copy it together, and then replace the icon inside with our icon.

Modify the startup page

same as modifying the icon
This picture is a bit abstract, don’t think about it, it’s art after all

Generate ad and ad-free versions

use:
You’re done, let’s try the effect. In order to install our custom App and the original App on the phone at the same time, we modifyapplicationId

xiaomi { applicationId 'com.xiaomi.makeapp' }

Compare the original version to see the effect

productFlavors (channel), buildTypes (Debug&Release), vanilla priority

Now we are clear that the files in productFlavors (channels) will overwrite the original App files.
If I now create a new folder called debug, the corresponding

buildTypes {
        debug {
            minifyEnabled false
            debuggable true
        }

, if you add some startup icons, App names, etc. to Debug to see what the effect will be
become the setting information in Debug.
According to

buildTypes > productFlavors

We can draw the rules, which are expressed as priorities for the convenience of reading:

Release &Debug > Channel Version Customization > Default Settings

That is, the high one will override the low setting

AB Test

What is AB Test

There is such a scenario: the product manager is confused, and he thinks that there are two schemes, scheme A and scheme B, on a page, but he doesn’t know which one to choose.
Solution: put both plan A and plan B online, count the user’s residence time, effective clicks, order conversion and other valid data for each plan, then calculate the efficiency of the two plans, and finally take the most efficient one.
Of course, you can also not use Build Variantsit, write both schemes to one page, then access the server, and the server will return to specify the method to be used for that scheme.

Demo code: https://github.com/zhouruikevin/makeapp

Leave a Comment

Your email address will not be published. Required fields are marked *