Androidgradle-Multi-channel packaging configuration (forwarding)

Source: Internet
Author: User

Demand

The domestic Android app release generally has many channels, in order to track the development situation, usually will customize a special apk for each channel.

General friends such as third-party statistics channel ID is defined as follows, take Wandoujia as an example

      <meta-data android:name="UMENG_CHANNEL" android:value="wandoujia" />

If you do not use third-party statistics, you can also define similar meta-data in Androidmanifest.xml

If each channel is manually modified, packaged, 10 several channels down??

We're still automated.

Solution Solutions

Gradle Android Plugin 0.10 new manifest merger

For custom placeholders replacements, use the following DSL to configure the placeholders values:

android {    defaultConfig {         manifestPlaceholders = [ activityLabel:"defaultName"]     }     productFlavors {        free {         }         pro { manifestPlaceholders = [ activityLabel:"proName" ]         }     

Manifest merger can replace the value of the corresponding key in the Manifest

Therefore, the product flavor + Manifestplaceholder can be used to replace the key of the corresponding channel.

If we have Wandoujia, Google Play, two channels, so to write

Androidmanifest.xml

        <meta-data android:name="UMENG_CHANNEL" android:value="$[CHANNEL_KET]" />

Build.gradle

        productFlavors {            wandoujia{                manifestPlaceholders = [ UMENG_CHANNEL_VALUE:name]            }            google_play{                manifestPlaceholders = [ UMENG_CHANNEL_VALUE:name]            }        }

OK, done, a few lines of code automatically generate the corresponding channel APK. In fact, the umeng_channel_value in manifest was replaced by Flavorbuild's name.

Can see the code inside each flavor, more verbose, but also in the simplification,

        productFlavors {            wandoujia{            }            google_play{            }        }        productFlavors.all { flavor ->            flavor.manifestPlaceholders = [ UMENG_CHANNEL_VALUE:name ]        }

A loop is done ~

--------------------------------------------------------------------------------------------------------------- ----------------

Original article Address: http://devyang.com/blog/2014/11/03/android-gradle-duo-qu-dao-da-bao-pei-zhi/

Androidgradle-Multi-channel packaging configuration (forwarding)

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.