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/>
First you have to AndroidManifest.xml change the meta-data following in the look:
<meta-data android:name= "Umeng_channel" android: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.
The latest update 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 can generate all the channel packs at once. But 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 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 value of the variable is the GRADLE_HOME root of the gradle, so the value of the variable is:C:\Users\yazhou\.gradle\wrapper\dists\gradle-2.1-all\27drb4udbjf4k88eh2ffdc0n55\gradle-2.1
There is also a PATH bin directory added to the system variable. gradleC:\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)