本文主要是介绍ANT多渠道打包,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
ANT多渠道打包
安装ANT
ant下载地址
http://ant.apache.org/
配置环境变量
新建ANT_HOME环境变量,值为ant所在的目录,然后将ANT_HOME/bin添加到path中
由于ant不支持循环需要下载ant-contrib
http://yunpan.cn/c3sn5NdCz7KTF 访问密码 45a2
将ant-contrib-1.0b3.jar文件放到ant目录下的lib目录
为Android项目生成Ant配置build.xml
首先创建一个安卓工程testAnt
打开命令行工具 cd到工程目录
android update project --name <project_name> --target <target_ID>--path <path_to_your_project>
例如
android update project --name testAnt --target 20 --path E:\workplace\testAnt
命令执行完毕会在工程的目录下创建 build.xml 和 local.properties两个文件
编写ant.properties
在工程目录创建一个ant.properties文件
key.alias=yourkeystore
key.alias.password=yourpassword
key.store=../keystore/XXXXX.keystore
market_channels=9990091,9990092,9990093,9990094,9990095app_name=testAnt
app_version=1.0
local.properties文件中添加出包路径
target.dir=E:\\workspace\\testAnt\\antApks
编写build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="testAnt" default="help"><!-- The local.properties file is created and updated by the 'android' tool.It contains the path to the SDK. It should *NOT* be checked intoVersion 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.dirThe name of the source directory. Default is 'src'.out.dirThe name of the output directory. Default is 'bin'.For other overridable properties, look at the beginning of the rulesfiles in the SDK, at tools/ant/build.xmlProperties related to the SDK location or the project target shouldbe updated using the 'android' tool with the 'update' action.This file is an integral part of the build system for yourapplication and should be checked into Version Control Systems.--><property file="ant.properties" /><echo>${market_channels}</echo> <echo>${app_version}</echo> <!-- 支持循环执行 --> <taskdef resource="net/sf/antcontrib/antcontrib.properties" > <classpath> <pathelement location="${ant.dir}/lib/ant-contrib-1.0b3.jar" /> </classpath> </taskdef> <echo>Run ant-contrib-1.0b3.jar ok</echo> <target name="deploy"> <foreach target="edit_and_build" list="${market_channels}" param="channel" delimiter=","> </foreach> </target> <target name="edit_and_build"> <echo>Run '${channel}' apk</echo> <replaceregexpencoding="utf-8"file="AndroidManifest.xml"flags="s"match="<meta\-data(\s+)android:name="DC_CHANNEL"(\s+)android:value="[a-zA-Z0-9]+""replace="<meta\-data android:name="DC_CHANNEL" android:value="${channel}""/><property name="out.final.file" location="${target.dir}/${app_version}/${app_name}.${channel}.apk" /> <antcall target="clean" /> <antcall target="release" /> </target> <!-- if sdk.dir was not set from one of the property file, thenget it from the ANDROID_HOME env var.This must be done before we load project.properties sincethe 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 librarydependencies. 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 yourapplication and should be checked into Version Control Systems. --><loadproperties srcFile="project.properties" /><!-- quick check on sdk.dir --><failmessage="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"--><!-- version-tag: 1 --><import file="${sdk.dir}/tools/ant/build.xml" /></project>
命令行到工程目录
ant deploy
这篇关于ANT多渠道打包的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!