Introduction to several common multi-channel (batch) packaging methods for Android

Source: Internet
Author: User

Multi-channel packaging, mainly in order to count the number of packages on different channels, the more channels, we need to hit the number of packages, this time, we can not use simple manual packaging to a one of the generation of different channel packages, we need more efficient packaging methods.

Statement Channel mode one:

Usually we distinguish channels in our manifest file application Use this to define the channel information:

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

Then in our Java code, we get the channel number in the following ways:

/** * Get Umeng channel number *  * @param context * @return Channel number */public static string Getchannel (context context) {String channel = "Bblivebyd"; try {applicationinfo info = Context.getpackagemanager (). Getapplicationinfo (Context.getpackagename (), Packagemanager.get_meta_data); if (info! = NULL && Info.metadata! = null) {String MetaData = Info.metaData.getStri Ng ("Umeng_channel"); Stringutil.isblank (MetaData)) {channel = MetaData;}}} catch (Namenotfoundexception e) {e.printstacktrace ();} return channel;}

There are several ways you can use this method of declaring channel numbers:

1. Friends Alliance Packaging Tools:

: Https://github.com/umeng/umeng-muti-channel-build-tool.


Easy to use, first in the normal way to make a separate signature package, and then open our download packaging tool, we recommend the use of the latest v3.2 (fixed some of the previous low version of the bug)


Click on the wrench to configure our application signature


At the bottom, give me a name for my configuration file. and then save.

Next, we will drag the signature package in front of the Friend Alliance Packaging tool plus here, such as the end of analysis, click a button to pack. There are problems with this approach, and you can look at the instructions on git.


2 Blue Shell Eclipse plugin package.

There is also a way of packaging, is the form of plug-in in eclipse, called Blue Shell, is a jar package, use is quite convenient, early company, multi-channel time, I also use this way, the advantage is: After installing the plug-in, only need to simple configuration, can be packaged in bulk.

Need to download a 200kb eclipse plugin.

Android Development AIDS-"blue shell" Eclipse Plugin usage Guide

1. Download the blue Shell Eclipse plugin

2. Install the blue Shell plugin , build Android Project

3. using configuration files, default profiles

4. Use the " Open in Explorer " feature

5. use the dependent updates feature

6. use the package release feature

1. Download the blue Shell Eclipse plugin

http://www.orchidshell.com/


Unzip Orchidshell.rar after download


Confirm that the folder path is Orchidshell---eclipse---plugins

2. Install the blue Shell plugin, build Android project

After installing the Eclipse plugin and copying the Orchidshell folder to the Dropins folder in Eclipse, start (restart) eclipse

Build Android Project


Right-click on the project to see the menu "Blue Shell", indicating the successful installation

3. Use the "Open in Explorer" feature

Click the Open menu in Explorer in the Blue Shell menu to open the folder where the currently selected resource is located.

If the selected resource is a folder, then the plugin will open the folder directly

If the selected resource is a file, the plug-in opens the file's parent folder, and the file is selected


4. Using configuration files, default profiles

Blue shells using XML as a plug-in configuration file, when there is no configuration file in the project, and some features of the plug-in need to use the configuration file, the plugin will create a new default configuration file.

This configuration file refers to a common Android development kit. A keystore for signing is configured. You need to modify this configuration file according to your own situation. The following two features are described in detail.

5. Use the dependent Updates feature

By clicking on the "Dependent updates" menu in the right-click of the plugin, you can manage updates to the project's third-party dependency jar packages.

Third-party jar packages used here, using MAVEN to manage the organization of JAR packages

It should be noted that the jar package here must have a unified download site. The site can be any MAVEN library or MAVEN library image. If you own a team server, you can also build a MAVEN library yourself to manage common common components.

After clicking on the menu, the update process will be played on the Eclipse console.

Note that if the configuration file is not configured correctly, some error prompts may be reported and the configuration file can be modified based on the error prompt.

6. Use the Package release feature

By clicking on the "Pack and Go" menu in the Blue Shell menu, you can individually package the project by channel, and you can automatically sign the APK file during the packaging process.

Note Before you package the release, you need to modify the corresponding items in the configuration file:

Where channels keyname= "" refers to the name of the application level <Meta-data> that is configured in your Androidmanifest.xml file. For example:

<meta-data android:value= "andao007.com" android:name= "umeng_channel"/>

<meta-data android:value= "andao007.com" android:name= "gfan_cpid"/>

Here is the Friend League statistics SDK and Jifeng Web Statistics SDK, so the name is "Umeng_channel,gfan_cpid", you can modify the statistical SDK for your own application of the channel project identifier, if there are multiple, use a comma separated by commas.

<channel value= "andao007.com"/>

Is the one that corresponds to each channel name you want to package, which is the identifier for the channel in the Statistics SDK. For each channel written here, the plugin automatically modifies the value in Meta-data for it and packs it into an apk file. Then sign the apk file.

<keystore path= "F:\Repos\android\keystore\common\common.key" passwd= "123456" >

<alias name= "Marsor_common" passwd= "123456"/>

</keystore>

The keystore here is the personal key you used to sign the APK file. You need to modify path to your KeyStore path, passwd the password for the KeyStore.

The following alias refers to each key corresponding to the alias, and the corresponding password. If you have multiple alias, you can specify here, the plugin will choose the first available alias and the password corresponding key key to your apk file signature.

<outpath value= "F:\Repos\android\keystore\output\"/>

This path is where your APK file is automatically packaged and stored after it is generated. Note The plugin creates a folder with your project name under this path.


Description Documentation & Plugin Download

3. Gradle multi-channel packaging, relatively new, easy to use


I have not used Android studio to hit the signature package, so we first paste the method of generating signatures:


Click on Android Studio Build and choose Generate signed APK.


Select Create New Key store:


J Fill out Click OK


Then next select the output apk location.


Next talk about Gradle multi-channel packaging

1. Defining placeholders in Androidmanifest.xml


<meta-data
Android:name= "Umeng_channel"
Android:value= "${umeng_channel_value}"/>




2. Replace the placeholder in the module's gradle script

productflavors {
Wangdoujia {
Manifestplaceholders = [Umeng_channel_value: "Wangdoujia"]
}
Xiaomi {
Manifestplaceholders = [Umeng_channel_value: "Xiaomi"]
}
Anzhi {
Manifestplaceholders = [Umeng_channel_value: "Anzhi"]
}
}


More multi-channel words are added according to the above format, add finished click Build----->generate signed apk.


Statement Channel mode two:Android Bulk Pack speed up-1 minutes 900 markets not a dream

The last kind of packaging, on the internet also has a lot of information, is based on the United States Group Packaging principle, the production of packaging tools.

You can see the article here.

Android Bulk Pack speed up-1 minutes 900 markets not a dream

Normal packaging method time is longer, is that need to modify the manifest file

<meta-data
Android:name= "Umeng_channel"
Android:value= "${umeng_channel_value}"/>


Value, and then continue signing, so time consuming.


The following is a package of ideas from the United States: (Original American group Android Automation Tour-Generate channel package)


If you can directly modify the APK channel number, and do not need to re-sign can save a lot of packaging time. Fortunately, we have found this way. Directly unzip the apk, the extracted root directory will have a meta-inf directory, as shown in:

If you add an empty file within the meta-inf directory, you do not have to re-sign the app. Therefore, you can uniquely identify a channel by adding different empty files for different channels of application.


After adding the empty channel file directory, the META-INFO directory has a more than one named mtchannel_meituan empty file:

You can then read the empty channel file name in the Java code:

public static String Getchannel (context context) {ApplicationInfo appinfo = Context.getapplicationinfo ();        String SourceDir = Appinfo.sourcedir;        String ret = "";        ZipFile zipfile = null;            try {zipfile = new ZipFile (SourceDir);            enumeration<?> entries = Zipfile.entries ();                while (Entries.hasmoreelements ()) {ZipEntry entry = ((ZipEntry) entries.nextelement ());                String entryName = Entry.getname ();                    if (Entryname.startswith ("Mtchannel")) {ret = EntryName;                Break        }}} catch (IOException e) {e.printstacktrace ();                } finally {if (ZipFile! = null) {try {zipfile.close ();                } catch (IOException e) {e.printstacktrace ();        }}} string[] split = Ret.split ("_"); if (split!)= null && split.length >= 2) {return ret.substring (split[0].length () + 1);        } else {return ""; }    }

This way, each dozen a channel package only need to copy an apk, in the META-INF add a channel number named empty file can be. This packaging is very fast, and more than 900 channels can be played in less than a minute.


According to the ideas provided by the United States Regiment, add an empty file as channel in Meta-info to meet our channel requirements, so we can reduce the packing time without the need of signature .

so with the Android Bulk Pack speed up-1 minutes 900 markets not the dream side of the article.


here are the specific steps:

Get ready


Download python:https://www.python.org
Download scripts written by others: Https://github.com/GavinCT/AndroidMultiChannelBuildTool

# # #步骤

1. Copy ' Channelutil.java ' into the project.
2. Obtain the channel number by using the Channelutil.getchannel (this) method in the code.
3. Install Python.
4. '. Pythontool\info\channel.txt ', inside to add the channels you want.
5. Place the apk into the ' multichannelbuildtool.py ' directory, double-click ' multichannelbuildtool.py ' to execute the script and complete the multi-channel packaging.

Here's a demonstration of packaging




I've configured 65 packages here, and I'm finished in a flash.

And the channel configuration is also very convenient, in the special Channel.txt can be configured.



Summarize

Comparison of various packaging methods:

Speed, the last way is invincible fast, and the use is very convenient, just need us to manually hit a signature package, and then only need to script to execute.


Umeng packaging tools, ordinary package can also, but more channels, configuration trouble, and contains so dynamic link library apk packaging may be problematic


Blue Shell Eclipse Packaging plug-in, I used to use the packaging method, faster than the United States to pack the idea of packaging slow, but generally not wrong.



Data are collected and on the Internet, if you have a good idea to share a lot.



Attach the last tool for packaging: http://download.csdn.net/detail/u011733020/9496464

Introduction to several common multi-channel (batch) packaging methods for Android

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.