[Android Studio] Android Studio Multi-channel packaging (Super Lite)

Source: Internet
Author: User

Reprint: http://xuyazhou.com/archives/461

http://relex.me/using-manifestplaceholders/

Recently used android studio to develop, in the development and release of the time, encountered a multi-channel packaging problem, because the company is a seven-channel package for distribution, because each time to AndroidManifest.xml modify the value of the channel, it is very troublesome ...

Finally went to Google, found some methods, is in the gradle file to switch a variety of different AndroidManifest.xml files, it feels too troublesome ... After searching for some, send some people write all the same, found a gradle use manifestPlaceholders this attribute to replace the channel value method, but I follow this method, no success, I went to the official documents to complete. Let's talk about how to achieve it.

The general use of the channel statistics is no more than UF or other such, today to the Friends of the Alliance for example Bar.
Channel information generally AndroidManifest.xml modifies the following values in:

<android:name= "Umeng_channel"  android:value= "Wandoujia" />

First you have to AndroidManifest.xml change the meta-data following in the look:

< Meta-data     android:name= "Umeng_channel"    android:value= "${umeng_channel_ VALUE} "/>

The ${UMENG_CHANNEL_VALUE} value in it is the value of the custom configuration in which you are in gradle .

build.gradleThe file is productFlavors written using this:

Which [UMENG_CHANNEL_VALUE: "wandoujia"] is ${UMENG_CHANNEL_VALUE} the corresponding value.

Latest Updates
Later found that the above repeated code too much, on the internet and found a more concise wording

where name the value pairs correspond to each productFlavors of the option values, thus achieving the purpose of automatically replacing channel values.

When you build the APK, you select the appropriate Flavors package to generate the specified channel, and the resulting apk will automatically add the appropriate channel suffix, which is very convenient and intuitive. You can decompile your own validation.

Generate all channel packages at once

There is a command-line tool in the Android Studio sidebar Terminal that CMD automatically switches to the current project directory when it is opened.

Some projects will have graldew.bat this file, you can enter this command:

Gradlew Assemblerelease
You can generate all the channel packs at once.
However, I generally do not recommend the use of this command, Gradlew the Gralde version of this command can not be controlled, sometimes inexplicably download the old version of the Gradle
So I personally recommend that you use the following usage.

First find gralde The root directory, add two environment variables in the system variables:

The variable name is: The GRADLE_HOME value of the variable is the root directory of Gradle;
So the variable value is:C:\Users\yazhou\.gradle\wrapper\dists\gradle-2.1-all\27drb4udbjf4k88eh2ffdc0n55\gradle-2.1

There is also a PATH bin directory added in the system variable gradle
Mine is.C:\Users\yazhou\.gradle\wrapper\dists\gradle-2.1-all\27drb4udbjf4k88eh2ffdc0n55\gradle-2.1\bin

The configuration is complete here, and then Terminal gradle assembleRelease you can generate all the channel packs in one shot.

All the generated apk is under the project build\outputs\apk .

What if you just want to generate a package for a single channel?

Open the Gradle Tasks panel (right sidebar) of Android Studio, and you'll find that the module has many more tasks, as shown in.

You can either double-click the task directly to generate the APK, or you can generate it separately from the command line, such as

Gradle Assemblewandoujiarelease

Multi-channel packaging is very fast from now on, and today it is written here, and later Android Studio has the corresponding tips or will share to everyone.

Reference: Http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger
Http://www.cnblogs.com/shanpow/p/4097320.html

[Android Studio] Android Studio Multi-channel packaging (Super Lite)

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.