Multi-channel packaging for Android

Source: Internet
Author: User

The source of this article: http://www.cnblogs.com/0616--ataozhijia/p/4203997.html

Here is an example of the Friends League.

The project is on the line, to do a multi-channel packaging. Otherwise, each time in the Androidmanifest.xml file to modify:

<meta-data android:name= "Umeng_channel" android:value= "Wandoujia"/>

Every time you change the value of value, the egg hurts.

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:

--= [Umeng_channel_value:name]}}

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.

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.

Multi-channel packaging for Android

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.