Android Multi-channel packaging

Source: Internet
Author: User

Android multi-channel packaging principle

In the manifest file, a different metadata tag is set inside the application tag, and the value within this matedata can be obtained through the Java API.

The multi-channel packaging technology provided by Friends Alliance
  1. Add the following code to the manifest file as required by Umeng

    <meta-data           android:name="UMENG_CHANNEL"           android:value="你自己申请的key" />
  2. If you write a value in value, you will be able to fix only one channel per package, so change to the following way

    <meta-data           android:name="UMENG_CHANNEL"           android:value="${UMENG_CHANNEL_VALUE}" />

    Using placeholders, add the following code to the Build.gradle's Android tab to differentiate the channel information. This placeholder and the OGNL expression in the spring frame work a bit like

    productFlavors{        huawei{            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "huawei"]        }        xiaomi{            manifestPlaceholders=[UMENG_CHANNEL_VALUE: "xiaomi"]        }    }

    Can be shortened to the following content

    productFlavors{  huawei{  }  xiaomi{  } } productFlavors.all { flavor ->  flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] }

    If you want to include version information, you can modify it to the following configuration

    productFlavors{    huawei{    }    xiaomi{    } } productFlavors.all { flavor ->    flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] } applicationVariants.all { variant ->    variant.outputs.each { output ->        def outputFile = output.outputFile        if (outputFile != null && outputFile.name.endsWith(‘.apk‘)) {            def fileName = outputFile.name.replace(".apk", "-${defaultConfig.versionName}.apk")            output.outputFile = new File(outputFile.parent, fileName)        }    } }

    The only way to get the channel information in the code is to easily send it to the server for data statistics.

    private String getChannel() {   try {       PackageManager pm = getPackageManager();       ApplicationInfo appInfo = pm.getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);       return appInfo.metaData.getString("UMENG_CHANNEL");   } catch (PackageManager.NameNotFoundException ignored) {   }   return "";}
Additional Trivia

When the computer is connected to more than one Android device, when using the ADB shell to enter different devices, you can add parameters

Adb-s serial number Install/shell and other commands

View Sequence Good

ADB devices

The first column that displays the result is the serial number

Android Multi-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.