ANT多渠道打包

ANT多渠道打包

安装ANT

ant下载地址

配置环境变量
新建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,9990095

app_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 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 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
         be updated using the 'android' tool with the 'update' action.

         This file is an integral part of the build system for your
         application 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>  

        <replaceregexp
            encoding="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, 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 should be 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 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



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱我呦呦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值