Ready for Android app release-Generate channel packs

Source: Internet
Author: User

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

<meta-data    android:name="CHANNEL_NAME"    android:value="CHANNEL_VALUE" />

Then replace the Channel_value value with the corresponding channel name. We can use Gradle's flavor to do it for us.

 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 to automatically update, some channel department automatically update, this time need a variable to indicate. We let all channels support automatic Updates by default, so that the pea pods do not update automatically.

defaultConfig {        "boolean""AUTO_UPDATES""true"    }
productFlavors {        wandoujia {            "boolean""AUTO_UPDATES""false"        }}

This variable can be obtained in the program

boolean autoUpdate=BuildConfig.AUTO_UPDATES;

Even sometimes you need to change the name of the generated apk so that you can define the generated name yourself

//Get Product namedefGetproductname () {return "ProductName"}//Get timestampdefGetDate () {defDate =NewDate ()defFormatteddate = Date.format (' YYYYMMDDHHMM ')returnformatteddate}android {...//Modify the generated apk nameApplicationvariants.all {variant-variant.outputs.each {output-defOldFile = Output.outputfiledefNewName ="';if(Variant.buildType.name.equals (' Release ')) {defReleaseapkname = Getproductname () +"-v${defaultconfig.versionname}-"+ variant.productflavors[0].name +'-signed.apk 'Output.outputfile =NewFile (Oldfile.parent, Releaseapkname)}if(Variant.buildType.name.equals (' Beta ') {newName = Getproductname () +"-v${defaultconfig.versionname}-"+ variant.productflavors[0].name +"-build"+ getDate () +". apk"Output.outputfile =NewFile (Oldfile.parent, NewName)}if(Variant.buildType.name.equals (' Debug ') {newName = Getproductname () +"-v${defaultconfig.versionname}-"+ variant.productflavors[0].name +"-debug"+ getDate () +". apk"Output.outputfile =NewFile (Oldfile.parent, NewName)}}}

Finally, we also need to get our channel name in the program to do some follow-up operations, such as doing some statistical work

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

When everything is done, we can create a channel bundle.
Open the terminal and enter the following command to generate all the channel packs.

gradlew assembleRelease

You can also click the Gradle button on the right side of Andorid studio, which has a circular execute Gradle task button in the popup window, command Line input Assemblerelease Click OK can also generate all channel packages

It takes a little time to generate all the channel packages, and all the packages that are generated in the APP/BUILD/OUTPUTS/APK directory after the build is complete. Upload the corresponding package to the corresponding channel.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Ready for Android app release-Generate channel packs

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.