Android Studio multi-channel Packaging

Source: Internet
Author: User

Android Studio multi-channel Packaging
Before developing an APP to upload the APP to the APP market, we sometimes encounter the problem of creating multiple apk packages based on different platforms. Due to the large number of Android app markets, the mainstream app markets include app treasure, Baidu mobile assistant, and pods. It is very troublesome to package one by one, but it is usually because some app marketing platforms have special requirements on the boot page, or they need to add their logo to the advertisement page on the second screen (when applying for the app market to start the market) therefore, multi-channel packaging is a task that must be done. Today I will talk about how to learn and implement multi-channel packaging. 1. create a small project, and create a class "TheSecondActivty (second screen advertisement page)" and its layout file "activity_second". Then open the configuration file and add a "meta-data", as shown in

 
"XIAO_GUIDANCE" is a basis for judgment in the code, and "XIAO_GUIDANCE_VALUE" is used in the build. gradle file below. If the boot pages of other channels need to be set separately, you can add a similar met-data. 2. open the build under the app. in the gradle file, note that this is selected in the figure, rather than the one at the bottom: after opening, add the following two pieces of code to this configuration file, for example: productFlavors {
Channel name {}
}
ProductFlavors. all {
Flavor-> flavor. manifestPlaceholders = [name of the value set for meta-data in the configuration file: name]
} 3. open the class on the second screen advertisement page, obtain the meta-data through ApplicationInfo, and determine whether meta-data contains "xiaomi". The "xiaomi" here corresponds to the channel name above, set the display picture on the second screen advertisement page. The specific code is as follows, which is very simple:
try {    ApplicationInfo appInfo = this.getPackageManager().getApplicationInfo(getPackageName(),            PackageManager.GET_META_DATA);    String reStr = appInfo.metaData.getString("XIAOMI_GUIDANCE");    if(reStr.equals("xiaomi")) {        rlBackground.setBackgroundResource(R.drawable.guidance_xiaomi);    } else {        rlBackground.setBackgroundResource(R.drawable.guidance);    }} catch (PackageManager.NameNotFoundException e) {    e.printStackTrace();}
4. after writing the code, you can package it. The simple packaging process is mentioned in my previous blog, so I won't talk about it here. directly, as shown in the Flavors column, there are two options, that is, we are building. channels added in gradle: after the package is completed, two Apk files shown in Figure 5 will appear in the project. finally, check the running and view the image display. Here, we have achieved multi-channel packaging. On the left is Xiaomi's (with a logo), and on the right is app's (without a logo ):

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.