Android Studio Sub-channel packaging

Source: Internet
Author: User

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
    1. 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.

    2. 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.
    1. 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

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.