使用ANT+Umeng工具实现多渠道打包编译APK

Android app开发完成以后第一项工作就是推广,因为国内的应用市场太多,APK会发布到各个应用商店,所以对每个渠道的推广效果进行监控就变的很有必要。
我个人采用了ANT+Umeng多渠道打包工具解决了上面这个问题。很多大牛一个ANT就搞定所有事了。之前在网上研究了很多关于ANT多渠道自动打包的文章,看的很累。如果不追求极致的话,采用我目前的方法效果也是一样的。好了,马上进入正题。
我使用的ADT版本是22.62,关于ANT的编译会用到3个文件:
build.xml
local.properties
ant.properties
平时我们调试的时候Eclipse会结合ANT自动帮我们生成Debug签名版的APK,所以我想到系统应该在某个地方已经配置好相关的build.xml文件了。果不其然在ANDROID_SDK目录下发现了一个Build文件(sdk/tools/ant/build.xml),这应该就是Debug的时候ANT所使用的build文件了。所以在我自己写的build文件中就引用到了它,同时也引用到local.propertiesant.properties这两个文件。

build.xml具体内容如下:


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

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

local.properties在这里的作用就是指定ANDROID_SDK的路径
local.properties详细内容如下:

   # This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.

# location of the SDK. This is only used by Ant
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=D:\\adt-bundle-windows-x86-20140321-20140805\\adt-bundle-windows-x86-20140321\\sdk

ant.properties 文件中需要指定签名证书,别名,签名密码等。
ant.properties 详细内容如下:

# This file is used to override default values used by the Ant build system.
#
# This file must be checked into Version Control Systems, as it is
# integral to the build system of your project.

# This file is only used by the Ant script.

# You can use this to override default values such as
#  'source.dir' for the location of your java source folder and
#  'out.dir' for the location of your output folder.

# You can also use it define how the release builds are signed by declaring
# the following properties:
#  'key.store' for the location of your keystore and
#  'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.

key.store=E:\\***\\***
key.alias=*****
key.store.password=****
key.alias.password=****

把这3个文件放到Eclipse项目的根目录:
请输入图片描述

最后运行build文件就可以编译打包了。
如果你在项目中用到了其他的第三方项目工程,那么依样画葫芦即可(复制这3份文件到你所引用的工程文件根目录即可)

关于多渠道打包,使用Umeng的工具即可,傻瓜式操作没什么好讲的。去官网下载吧:https://github.com/umeng/umeng-muti-channel-build-tool

如果有初学者不明白的可以邮件给我:wuyiqi2003@gmail.com

阅读 5.5k更新于 2014-08-21
推荐阅读
517
用户专栏

0 人关注
1 篇文章
专栏主页
目录