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