Android Multi-channel packaging

Source: Internet
Author: User

1, packerng-type packaging

The apk file used by Android app is a zip file with signature information, according to the ZIP file format specification, each zip file must have a part called Central Directory Record, the last part of this CDR is called "End of Central directory record, which contains some metadata, at the end of which is a comment for the zip file. Note contains comment length and file comment Two fields, which represent the length of the comment content, which is the content of the comment, correct modification of this part will not damage the zip file, using this field, we can add some custom data, The PACKERNG project is where you add and read channel information.

<a href= ' Https://github.com/mcxiaoke/packer-ng-plugin/blob/master/sample/build.gradle ' > corresponds to GitHub address </a >


2, Meta-inf-type packaging

can only modify the existing APK channel logo, fast, batch, simple principle


3, Gradle dozen channel Bag

The basic principle is to utilize Gradle's manifest merger function

The main purpose of this feature is to be able to replace the contents of Androidmanifest.xml at runtime

The first step is to configure Meta-data in Androidmanifest.xml.

<meta-data

android:name= "Umeng_channel"

android:value= "${umeng_channel_value}" />

The second step is to add the placeholder definition to the defaultconfig of the module's Build.gradle file.


Android {

    ...


Defaultconfig {

        ...

manifestplaceholders = [umeng_channel_value:"Default_channel" ]

}

}


There are two functions here, one is to declare that Umeng_channel_value is the placeholder of the replaceable value, and the other is to set the default value for it.



The third step is to add the Productflavors configuration to the module's Build.gradle file.

Android {

productflavors {

default_channel{}

wandoujia{}

        _ the {}

yingyongbao{}

xiaomi{}

baidu{}

huawei{}

jifeng{}

}

Productflavors.all {Flavor

Flavor.manifestplaceholders = [Umeng_channel_value:name]

}

}



Fourth step build all channel packages at once


Run Gradlew assemblerelease to the project directory.

You can see that this compilation has produced the corresponding productflavors segment of the different channel packages.


You can decompile each apk, open the androidmanifest.xml to see, found that the Friend League this section of the configuration has been modified accordingly.


<meta-data

android:name= "Umeng_channel"

android:value= "Default_channel" />


You can also use Gradle to generate a separate channel package

such as Gradlew Assemblewandoujiarelease


Android Multi-channel packaging

Related Article

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.