Gradle implements two simple multi-channel packaging methods.

Source: Internet
Author: User

Gradle implements two simple multi-channel packaging methods.

I was planning to send an official technical document for Android today-Chapter 5 of "Gradle plug-in user guide", but I had to postpone it because it was not translated last night and there were still a few paragraphs.

Today, let's talk about how to use Gradle for multi-channel packaging like umeng.

This article is original and reprinted. Please note the source on CSDN:

Http://blog.csdn.net/maosidiaoxian/article/details/42000913

Currently, I have two methods, both of which are very simple and use the productFlavors IN THE Gradle Android plug-in.

Taking UMENG's multi-channel packaging as an example, we need to package the following channels: UMENG, WANDOUJIA, YINGYONGBAO.

The first method is to create a file.

After writing our code, create the umeng, wandoujia, and yingyongbao folders in the same directory as main under app/src. Each of these three folders has only one AndroidManifest. xml file, the file only needs to be as follows:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="your.package.name">    <application>          <meta-data android:name="UMENG_CHANNEL" android:value="UMENG"/>    </application></manifest>
Note that the value above must correspond to your channel name. For example, wandoujia corresponds to the channel name (such as WANDOUJAI) on your pods ).

Add the productFlavors node to the android {} node of your build. gradle. The Code is as follows:

Android {// here is your other configuration productFlavors {umeng {} wandoujai {} yingyongbao {}} // your other configuration}
Note that the flavors name must match the name of your folder. After this configuration, the multi-channel APK is built.


The second method does not need to create those files. It uses another function in the Gradle Android plug-in, manifestPlaceholders.

In this method, you only need to configure the umeng channel in AndroidManifest. xml as follows:

        <meta-data            android:name="UMENG_CHANNEL"            android:value="${CHANNEL_NAME}" />

Then use productFlavors, but its configuration is as follows:

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 example, we can also specify a default channel name, if needed. The default value is to add the following content to the defaultConfig node:

        manifestPlaceholders = [ CHANNEL_NAME:"Unspecified"]
Replace Unspecified with your actual default channel name.

Using this configuration of manifestPlaceholders also applies to other configurations of manifest. For example, you need to specify different startup activities in the apk released through different channels. For example, when published in pods, The started Activity displays the initial interface of pods. In pods, the app started the initial interface of pods (haha, a little bad ), you can use $ {activity_name} for the value of your activity, and configure the value of $ {activity_name} In productFlavors.


This article is original. For more information, see the source on the CSDN blog:

Http://blog.csdn.net/maosidiaoxian/article/details/42000913

Or by: Geek_Soledad

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: info-contact@alibabacloud.com 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.