Prepare for Android Application release-generate channel package

Source: Internet
Author: User

Prepare for Android Application release-generate channel package

We need to use a variable to indicate the channel of the app. Generally, we can declare it under the application node in manifest, as shown below.


  

Then, replace the value of CHANNEL_VALUE with the corresponding channel name. We can use the flavor of gradle to complete it for us.

        flavor.manifestPlaceholders = [CHANNEL_VALUE: name]    } data-snippet-id=ext.ce943ea9d51c68f4f0a3339e1de051bc data-snippet-saved=false data-csrftoken=Eq6LIWAR-4Cx8Srvsca1PFMG7mGEOwWNPoGc data-codota-status=done> productFlavors {        wandoujia {}        qihu360 {}        baidu {}        hiapk {}        shoujizhushou {}        tencent {}        xiaomi {}        anzhi {}        uc {}        appchina {}        wangyi {}        mumayi {}        huawei {}        lenovo {}        flyme {}    }    productFlavors.all { flavor ->        flavor.manifestPlaceholders = [CHANNEL_VALUE: name]    }

Of course, sometimes we need to configure some channels for automatic updates, and some channels for Automatic Updates. At this time, we need a variable to indicate. By default, automatic updates are supported for all channels, so that automatic updates are not performed for pods.

defaultConfig {        buildConfigField boolean, AUTO_UPDATES, true    }
productFlavors {        wandoujia {            buildConfigField boolean, AUTO_UPDATES, false        }}

This variable can be obtained in the program.

boolean autoUpdate=BuildConfig.AUTO_UPDATES;

You can even customize the name of the generated apk.

Variant. outputs. each {output-> def oldFile = output. outputFile def newName = ''; if (variant. buildType. name. equals ('release') {def releaseApkName = getProductName () +-v $ {defaconfig config. versionName}-+ variant. productFlavors [0]. name + '-signed.apk 'output. outputFile = new File (oldFile. parent, releaseApkName)} if (variant. buildType. name. equals ('beta ') {newName = getProductName () +-v $ {defaconfig config. versionName}-+ variant. productFlavors [0]. name +-build + getDate () +. apk output. outputFile = new File (oldFile. parent, newName)} if (variant. buildType. name. equals ('debug') {newName = getProductName () +-v $ {defaconfig config. versionName}-+ variant. productFlavors [0]. name +-debug + getDate () +. apk output. outputFile = new File (oldFile. parent, newName) }}} data-snippet-id = ext.2d8967d75590fed2f15bdfa52c0825b3 data-snippet-saved = false data-csrftoken = w6snEJhm-V_o5qFIgYY_rrEhmATollsIqVfA data-codota-status = done>// Obtain the product name def getProductName () {return ProductName} // obtain the timestamp def getDate () {def date = new Date () def formattedDate = date. format ('yyyymmddhhmm ') return formattedDate} android {... // modify the generated apk name applicationVariants. all {variant-> variant. outputs. each {output-> def oldFile = output. outputFile def newName = ''; if (variant. buildType. name. equals ('release') {def releaseApkName = getProductName () +-v $ {defaconfig config. versionName}-+ variant. productFlavors [0]. name + '-signed.apk 'output. outputFile = new File (oldFile. parent, releaseApkName)} if (variant. buildType. name. equals ('beta ') {newName = getProductName () +-v $ {defaconfig config. versionName}-+ variant. productFlavors [0]. name +-build + getDate () +. apk output. outputFile = new File (oldFile. parent, newName)} if (variant. buildType. name. equals ('debug') {newName = getProductName () +-v $ {defaconfig config. versionName}-+ variant. productFlavors [0]. name +-debug + getDate () +. apk output. outputFile = new File (oldFile. parent, newName )}}}}

Finally, we also need to obtain our channel name in the program for subsequent operations, such as some statistics and other work.

        String channel=AppUtil.getMetaValue(this,CHANNEL_NAME);        Log.d(TAG,channel);

After everything is done, we can generate a channel package.
Open the terminal, enter the following command and press enter to generate all channel packages.

gradlew assembleRelease

In addition, you can click the gradle button on the Right of andorid studio. In the pop-up window, there is a circular execute gradle task button. In command Line, enter assumerelease and click OK to generate all channel packages.

 

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.