Very simple multi-channel packaging method

Source: Internet
Author: User

Originally planned today to send Android official technical document translation-"Gradle plug-in User Guide" of the fifth chapter, but because last night did not finish translation, still a few paragraphs, so had to postpone.

Let's talk today about using Gradle to do multi-channel packaging like the Friends Alliance.

This article original, reproduced please note on the csdn on the source:

At present, I have mastered two methods, are very simple, with the Gradle Android plugin in the productflavors.

As an example of a friend's multi-channel package, let's say we need to package the following channels: Umeng, Wandoujia, Yingyongbao.

The first method is to create a file.

After we have finished writing our code, under APP/SRC, create the folder Umeng, Wandoujia, Yingyongbao, respectively, with the main sibling directory, Each of the three folders has only one androidmanifest.xml file, the file only needs to be as follows:

<manifest xmlns:android= ""    package= "" >    <application>          <meta-data android:name= "Umeng_channel" android:value= "Umeng"/>    </ Application></manifest>
Note that the value above should correspond to the name of your channel. For example, the Wandoujia should correspond to the channel name on your pea pod (e.g. Wandoujai).

Then in your Build.gradle android{} node, add the Productflavors node, the code is as follows:

Android {    //Here is your other configuration    productflavors{        umeng{  }        wandoujai {  }        yingyongbao{  }    }    //Your other configuration}
Note that the name of the flavors here corresponds to the name of your folder. Once this is configured, the multi-channel apk is built.

The second way, without creating those files, it uses another feature in the Gradle Android plugin, manifestplaceholders.

In this approach, you only need to configure the Androidmanifest.xml channel in this way:

        <meta-data            android:name= "Umeng_channel"            android:value= "${channel_name}"/>

Then use the same productflavors, but then it's configured like this:

Android {    //Your other configuration code    productflavors {        Yingyongbao {            manifestplaceholders = [Channel_name: " Yingyongbao "]        }        Umeng {            manifestplaceholders = [channel_name:" Umeng "]        }        Wandoujia {            Manifestplaceholders = [channel_name: "Wandoujia"]        }    }    //Your other Configuration code}

In the above, we can also specify a default channel name, if necessary. Specifying the default value is to add the following to the Defaultconfig node:

        Manifestplaceholders = [channel_name: "Unspecified"]
The unspecified here is replaced by your actual default channel name.

Using this configuration of Manifestplaceholders, the same applies to other configurations of manifest. For example, you need to specify different launch activity in the APK that is released from different channels. For example, in the Pea pod released, the activity shown is the start of the Pea pod interface, App Bao is launched in the app Bao first interface (haha, a bit bad), you can use the value of your activity ${activity_name} way, Then configure the value of this ${activity_name} inside the productflavors.

This article by 6K Bo Master Original, reproduced please indicate the source:

or Geek_soledad

This article by 6K Bo Master Original, reproduced please indicate the source:

or Geek_soledad

Very simple multi-channel packaging method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.