Ant Tools-Multi-channel auto-pack Android projects

Source: Internet
Author: User

(a) Ant introduction

Ant is an automated copy, compile, and publish build tool that is simple across platforms.

(ii) Ant use Prelude

1. Install the JDK and match the environment variables

2. Install the SDK and match the environment variables

3. The new Android SDK has its own ant in the/eclipse/plugins directory, if you want to download to http://ant.apache.org, the new environment variable ant_home to the ant directory, path is%ant_home%/ Lib

(iii) Compiling and publishing Android projects

1. Generate the Build.xml file

Run Android update project-p xxx (XXX for project path)

Automatic generation of Build.xml, local.properties two files under the project root directory

Build.xml has made the basic configuration and called the SDK itself with the Build.xml file,Local.properties has set the SDK directory

2. Packaging items

New ant.properties, put KeyStore signature information

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

Put zhangzhongcai.keystore signature file under root directory

If you do not specify Key.store.password and Key.alias.password, the input will be required during operation to improve security

Run Ant release package

(iv) multi-channel automated packaging

1. Multi-channel packaging needs to modify the configuration file, complete the channel information modification and packaging, ant itself does not have a for command, modify the XML file is not convenient, need to use the third-party extension package Ant-contrib, from here can be downloaded to, downloaded in the project in the new Lib folder into.

2. New Channel.properties Join Channel information

<span style= "FONT-SIZE:18PX;" >market_channels=anzhi,360,baidu</span>

3. Modify Build.xml support multi-channel automated packaging, there are two ways

(1) Add custom_rules.xml, write automated packaging scripts, pre-package initialization invokes Custom_rules.xml content

(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 should *not* is checked into Version Control Systems. --<property file= "local.properties"/> <!--the ant.properties file can created by you.         It is only edited by the ' Android ' tool to add properties to it.         The "the" to "change some Ant specific build properties. Here is some properties 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 the beginning of the rules files in the SDK, at Tools/ant/build.xml Properties related to the SDK location or the project target should is updated using the 'Android ' tool with the ' Update ' action. This file is a integral part of the build system for your application and should are checked into Version Control         Systems. --<property file= "ant.properties"/><property file= "channel.properties"/> <!--if Sdk.dir was n         OT set from one of the property file, then get it from the Android_home env var. This must is done before we load project.properties since the Proguard config can use Sdk.dir--<proper Ty 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 is stored in ant.properties (or of. Classpath for Eclipse projects). This file is a integral part of the build system for your application and should are checked into Version Control Systems.            --<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 was the place to put custom intermediary targets such as:-pre-build-pre-compile                           -post-compile (this was typically used for code obfuscation. Compiled code location: ${out.classes.absolute.dir} If The is not do 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 is, options:-Customize only one target:-Copy/pas             Te 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 must UPDA Te the value of Version-tag below to read ' custom ' instead of a integer, in order to avoid have your file be ov Erridden by tools such as "Android Update Project"--><!--Channel Pack packaging script ant Deploy--<!--read in Androidmanifest.x ML information for easy access to the software version number--&LT;XMLproperty file= "Androidmanifest.xml" prefix= "Appinf" collapseattributes= "true"/><taskdef resource= "net/sf/ Antcontrib/antcontrib.properties "> <classpath> <pathelement location="./lib/ant-contrib-1.0b3.ja  R "/> </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 "> <!--matching content is android:value=" * * * * "Android Oid:name= "Umeng_channel"--<regexp pattern= ' android:name= "Umeng_channel" android:value= "(. *)" '/&          Gt < replace it with android:value= "channel name" Android:name= "Umeng_channel" and <substitution expression= ' Android:valu after!--match E= "${channel}" android:name= "Umeng_channel" '/> <!--regular expressions require matching files of Androidmanifest.xml-<fil ESET dir= "" includes="Androidmanifest.xml"/> </replaceregexp> <property name= "Out.release.file" location= "${out.absolute . dir}/${ant.project.name}_${channel}.apk "/> <!--packaged--<antcall target=" release "/> <! --Output channel package to bin/out directory--<copy tofile= "${out.absolute.dir}/out/${ant.project.name}v${appinf.manifest.android: versionname}_${channel}_release.apk "file=" bin/${ant.project.name}-release.apk "/> </target> <!-- Version-tag:1--<import file= "${sdk.dir}/tools/ant/build.xml"/></project>

By running the ant command in this directory, you can package the versions of each channel into the Bin/out directory


Ant Tools-Multi-channel auto-pack Android projects

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

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.