android Ant 批量多渠道打包!

参考: http://blog.sina.com.cn/s/blog_74c22b21010173f8.html


一直以来都是手动打包android程序,真可谓苦不堪言啊,以前试过用ant打包,但是失败了,最近刚到新公司,又开始研究ant这玩意了,查阅了网上一些文章,结合自己的情况,硬是要弄出来才行,这里就作下记录吧。


1,准备

ant打包自然需要ant,可以去http://ant.apache.org/下载解压,也可以使用eclipse自带的(如果有的话)。

验证ant是否安装好,在控制台输入Cmd 回车, ant 回车,如果出现:

   Buildfile: build.xml does not exist!
   Build failed

恭喜你已经ant配置成功!!

2,配置环境变量和添加扩展组件

在环境变量中需要添加ANT_HOME,JAVA_HOME,ANDROID_SDK_HOME等着几个变量(原因是有些写法使用了此变量,尽可能多的写出来避免错误),并且还要path变量将%ANT_HOME%\bin;%ANT_HOME%\lib;%JAVA_HOME%/lib;%JAVA_HOME%/bin等。

下载 ant-contrib-1.0b3.jar放在ant 的 lib文件夹下,(如果使用的是eclipse自带的,请配置ant变量并添加到指定位置如图,确保调用的ant包含有扩展组件)。

preferences配置


3,编写build.xml


<?xml version="1.0" encoding="UTF-8"?>
<!-- 项目名称yinyuedongting,可用全局替换为当前项目名称 -->
<project
    name="yinyuedongting"
    default="deploy" >

    <!--
         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" />

    <!--
         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 an env var"
        unless="sdk.dir" />

    <!--
     extension targets. Uncomment the ones where you want to do custom work
     in between standard targets



    -->
    <!--
    <target name="-pre-build">
    </target>
    <target name="-pre-compile">
    </target>

   
    <target name="-post-compile">
    </target>




    -->


    <!--
         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 -->

    <taskdef resource="net/sf/antcontrib/antcontrib.properties" >

        <classpath>

            <pathelement location="D:/androidDev/batch-package-tool/ant1.8.3/lib/ant-contrib-1.0b3.jar" />
        </classpath>
    </taskdef>

    <import file="${sdk.dir}/tools/ant/build.xml" />

    <target name="deploy" >

        <foreach
            delimiter=","
            list="${market_channels}"
            param="channel"
            target="modify_manifest" >
        </foreach>
    </target>

    <target name="modify_manifest" >

        <!-- <replaceregexp file="AndroidManifest.xml" encoding="utf-8" match="android:value="(.*)"" replace=""/> -->

        <replaceregexp
            byline="false"
            flags="g" >

            <regexp pattern="android:name="UMENG_CHANNEL" android:value="(.*)"" />

            <substitution expression="android:name="UMENG_CHANNEL" android:value="${channel}"" />

            <fileset
                dir=""
                includes="AndroidManifest.xml" />
        </replaceregexp>
        <!-- <property  name="out.release.file" value="${out.absolute.dir}/${channel}.apk"/> -->

        <antcall target="release" />

        <copy tofile="${gos.path}/yinyuedongting_${channel}.apk" >

            <fileset
                dir="${out.absolute.dir}/"
                includes="yinyuedongting-release.apk" />
        </copy>

        <delete includeEmptyDirs="true" >

            <fileset
                dir="${out.absolute.dir}"
                includes="**/*" />
        </delete>

        <echo message="===========================" />
    </target>

</project>

以上的可以全部拷贝,然后通过全局替换掉项目名称,例子中项目名称为yinyuedongting



4,配置local.properties

此处只有一个选项就是android sdk路径,

sdk.dir=D:\\adt-bundle-windows\\sdk,改为你自己的sdk路径,注意用双斜杠转义


5.配置ant.properties

application.package=com.yuanhang.yinyuedongting   程序包名
ant.project.name=yinyuedongting 项目名称
java.encoding=utf-8 项目编码

out.absolute.dir=d:/apk/compile  临时文件存放位置
gos.path=d:/apk/yinyuedongting   apk文件存放位置

key.store=D:/\u5F00\u53D1\u8D44\u6599\/rainie.keystore  秘钥所在位置
key.store.password=rainie  秘钥密码
key.alias=rainie   秘钥别名
key.alias.password=rainie  别名密码

app_version=1.0.0  版本
market_channels=default  渠道名称,要以逗号分隔,必须在一行内


注意使用的是友盟渠道,如果要修改则自行在build.xml中修改


以上这些都配置好后,即可巡行ant 打包应用,也可以通过eclipse插件快速运行编译指令,以上过程已运行成功,并且换了不同项目也同样没问题。

最后一个问题就是,这个ant的build.xml文件尚未对引用到library项目作出编译,所以有引用到library项目的不能运行成功,解决办法是将library项目所有资源文件copy到现有项目
中,方能编译成功。


资源文件下载地址:http://download.csdn.net/detail/luoxiangyu001/5344270


Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值