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)