Ant tool-multi-channel automatic packaging of android projects, ant package android Projects

Source: Internet
Author: User

Ant tool-multi-channel automatic packaging of android projects, ant package android Projects

(1) ant Introduction

Ant is an automated build tool for copying, compiling, and publishing. It is simple and cross-platform.


(2) Introduction to ant

1. Install jdk with Environment Variables

2. Install the sdk and use environment variables

3. The new version of the android sdk has built-in ant in the/eclipse/plugins directory, if you need to download to the http://ant.apache.org, new environment variable ANT_HOME ant directory, path is % ANT_HOME %/lib


(3) Compile and release the android Project

1. Generate the build. xml file

Run android update project-p xxx (xxx is the project path)

The build. xml and local. properties files are automatically generated under the project root directory.

The build. xml file that comes with the sdk has been basically configured and called. The local. properties directory has been set for the sdk.

2. Package the project

Create ant. properties and add the keystore signature information.

Key. store = zhangzhongcai. keystore
Key. store. password = xxx
Key. alias = xxx
Key. alias. password = xxx

Add the zhangzhongcai. keystore signature file to the root directory.

If key. store. password and key. alias. password are not specified, They are required during operation to improve security.

Run ant release to package


(4) automated multi-channel Packaging

1. to Package Multiple channels, you must modify the configuration file, modify the channel information, and then package. ant does not have the for command, and it is not convenient to modify the xml file. You must use the third-party extension package Ant-contrib, you can download it from here. After the download, create a new lib folder in the project and put it in.

2. Create channel. properties and add channel information

<span style="font-size:18px;">market_channels=anzhi,360,baidu</span>

3. You can modify build. xml to support automated packaging through multiple channels.

(1) Add custom_rules.xml to write the automated packaging script. The custom_rules.xml content is called during initialization before packaging.

(2) write the automated packaging script to build. xml as follows:

<? Xml version = "1.0" encoding = "UTF-8"?> <Project name = "TestRelease" default = "deploy"> <! -- The local. properties file is created and updated by the 'android' tool. it contains the path to the SDK. it shoshould ** NOT * be checked into Version Control Systems. --> <property file = "local. properties "/> <! -- The ant. properties file can be created by you. it is only edited by the 'android' tool to add properties to it. this is the place to change some Ant specific build properties. here are some properties you may want to change/update: source. dir The name of the source directory. default is 'src '. out. dir The name of the output directory. default is 'bin '. for other overridable properties, look at t He beginning of the rules files in the SDK, at tools/ant/build. xml Properties related to the SDK location or the project target shocould be updated using the 'android' tool with the 'update' action. this file is an integral part of the build system for your application and shoshould be checked into Version Control Systems. --> <property file = "ant. properties "/> <property file =" channel. properties "/> <! -- If sdk. dir was not set from one of the property file, then get it from the ANDROID_HOME env var. this must be done before we load project. properties since the proguard config can use sdk. dir --> <property environment = "env"/> <condition property = "sdk. dir "value =" $ {env. ANDROID_HOME} "> <isset property =" env. ANDROID_HOME "/> </condition> <! -- The project. properties file is created and updated by the 'android' tool, as well as ADT. this contains project specific properties such as project target, and library dependencies. lower level build properties are stored in ant. properties (or in. classpath for Eclipse projects ). this file is an integral part of the build system for your application and shoshould be checked into Version Control Sys Tems. --> <loadproperties srcFile = "project. properties"/> <! -- Quick check on sdk. dir --> <fail message = "sdk. dir is missing. make sure to generate local. properties using 'android update project' or to inject it through the ANDROID_HOME environment variable. "unless =" sdk. dir "/> <! -- Import per project custom build rules if present at the root of the project. this is the place to put custom intermediary targets such as:-pre-build-pre-compile-post-compile (This is typically used for code obfuscation. compiled code location: $ {out. classes. absolute. dir} If this is not done in place, override $ {out. dex. input. absolute. dir})-post-package-post-build-pre-clean --> <import file = "Custom_rules.xml" optional = "true"/> <! -- Import the actual build file. to customize existing targets, there are two options:-Customize only one target:-copy/paste the target into this file, * before * the <import> task. -customize it to your needs. -Customize the whole content of build. xml-copy/paste the content of the rules files (minus the top node) into this file, replacing the <import> task. -customize to your needs. ******* * ********************* IMPORTANT ***************** * ********** In all cases you must update the value of version-tag below to read 'custom' instead of an integer, in order to avoid having your file be overridden by tools such as "android update project" --> <! -- Channel package packaging script ant deploy --> <! -- Read AndroidManifest. xml Information for easy access to software version --> <xmlproperty file = "AndroidManifest. xml "prefix =" appinf "collapseAttributes =" true "/> <taskdef resource =" net/sf/antcontrib. properties "> <classpath> <pathelement location = ". /lib/ant-contrib-1.0b3.jar "/> </classpath> </taskdef> <target name =" deploy "> <foreach target =" modify_manifest "list =" $ {market_channels} "param = "channel" delimiter = ", "> </foreach> </ Target> <target name = "modify_manifest"> <replaceregexp flags = "g" byline = "false"> <! -- The matched content is android: value = "*****" android: name = "UMENG_CHANNEL" --> <regexp pattern = 'android: name = "UMENG_CHANNEL" android: value = "(. *) "'/> <! -- Replace it with android: value = "channel name" android: name = "UMENG_CHANNEL" --> <substitution expression = 'android: value = "$ {channel}" android: name = "UMENG_CHANNEL" '/> <! -- The file to be matched by the regular expression is AndroidManifest. xml --> <fileset dir = "" includes = "AndroidManifest. xml "/> </replaceregexp> <property name =" out. release. file "location =" $ {out. absolute. dir}/{ant.project.name=_{{channel}.apk "/> <! -- Package --> <antcall target = "release"/> <! -- Export the channel package to the bin/out directory --> <copy tofile = "$ {out. absolute. dir}/out/$ {ant. project. name} V $ {appinf. manifest. android: versionname1__zookeeper channel1__release.apk "file =" bin/zooant.project.name=-release.apk "/> </target> <! -- Version-tag: 1 --> <import file = "$ {sdk. dir}/tools/ant/build. xml"/> </project>

Run the ant command in this directory to package the versions of each channel to the bin/out directory.


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.