Two simple multi-channel packaging methods implemented by Gradle

Source: Internet
Author: User

Android multi-channel packaging Gradle multi-channel packaging friends multi-channel packaging productflavors

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:

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

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:

[Plain]View Plaincopy
    1. <manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
    2. Package= "Your.package.name" >
    3. <application>
    4. <meta-data android:name= "Umeng_channel" android:value= "Umeng"/>
    5. </application>
    6. </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:

[Plain]View Plaincopy
    1. Android {
    2. Here is your other configuration
    3. productflavors{
    4. umeng{}
    5. Wandoujai {}
    6. yingyongbao{}
    7. }
    8. Your other configuration
    9. }
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:

[Plain]View Plaincopy
    1. <meta-data
    2. Android:name= "Umeng_channel"
    3. Android:value= "${channel_name}"/>

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

[Plain]View Plaincopy
  1. Android {
  2. Your other configuration code
  3. productflavors {
  4. Yingyongbao {
  5. Manifestplaceholders = [channel_name: "Yingyongbao"]
  6. }
  7. Umeng {
  8. Manifestplaceholders = [channel_name: "Umeng"]
  9. }
  10. Wandoujia {
  11. Manifestplaceholders = [channel_name: "Wandoujia"]
  12. }
  13. }
  14. Your other configuration code
  15. }

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:

[Plain]View Plaincopy
    1. 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 original, reprint please indicate CSDN blog on the Source:

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

or Geek_soledad

      • Previous Gradle 1.12 User Guide Translation-21st chapter. Gradle Plug-in
      • Next Android official technical document Translator--gradle Plugin User Guide (5)

Two simple multi-channel packaging methods implemented by Gradle

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.