today, a small partner asked me how to sub-channel packaging, I turned over the previous project, found a demo to him. The basic steps are still relatively simple. Environment: Use Android Studio or directly with Gradle
- Add a placeholder to the Androidmanifest.xml, the name of the placeholder is determined by the statistical services you use, and if you are using a friend alliance, you need to include a meta-data as shown below:
<Meta-data android: Name="Umeng_channel" Android: Value="${channel_value}"/>
The name of the friend League is Umeng_channel.
- Modify the project's Gradle file and add the following code to the Gradle
Android {
......
productflavors {
SHB {}
QQ {}
Wandoujia {}
Baidu {}
c360 {}
Huawei {}
Xiaomi {}
Lenovo {}
Meizhu {}
}
Productflavors.All {Flavor -
Flavor.Manifestplaceholders=[Channel_value: Name]
}
......
}
Productflavors inside is the configuration of different branch packages flavor-Flavor.manifestplaceholders = [Channel_value: Name] is the androidmanifest.xml inside the"${channel_value}"Replace it with your own defined name.
- Different channels of APK file automatically with different names
Different packages with different names are also for the convenience of managing the package files themselves. The name format that we want the APK to generate is: Software name-versioncode-versionnumber-channel name. apk
We need to add the following code to the Gradle buildtypes {
Release {
Applicationvariants.All {Variant -
Variant.Outputs.Each {Output -
defFlavor="Default";
if(variant.Productflavors.Size ()>0)
Flavor=Variant.Productflavors.Get0);
defDate=NewDate();
defFormatteddate=Date.Format' YyyyMMdd ')
defVersioncode=Variant.Versioncode
defVersionname=Defaultconfig.Versionname
defFile=Output.OutputFile
printlnVariant
printlnVersionname
defFinalname="release-" +Versioncode+"-V"+Versionname+"-"+Flavor.Name+". apk"
Output.OutputFile= NewFile(File.Parent, Finalname)
}
}
}
Don't forget to define the version number in Gradle, as follows: Defaultconfig {
Versioncode -
Versionname"1.1.04.23"
}
Here, the added code is added. Run a look at the menu: Build->generate signed apk in the menu to select the desired channel.
Haha, this will make the generated package files available to the operation.
Android Studio Sub-channel packaging