码迷,mamicode.com
首页 > 移动开发 > 详细

Android批量生成渠道包

时间:2015-01-07 13:11:25      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:android   ant   

1、在www.apache.org上下载ant并在自己计算机上配置Ant的运行环境(我的资源中共享了从Apache下载的ant包,大家也可以自己去官网下载)

     技术分享

 

技术分享

 

2、检测是否安装成功

开始——>运行——cmd——输入ant回车,如果出现以下提示,则表示Ant环境设置已经配置好

技术分享

 

3、为了能让ant能批量生成android的apk文件,需要将ant-contrib-1.0b3.jar(我的资源中有此文件可下载)文件放到ant的lib目录中去

技术分享

4、在Eclipse中指定Ant目录(不要用Eclipse自带的Ant)Window——>prefercens

技术分享

 

5、创建Android测试批量打包工程

在工程下创建几个文件:(也就是项目的根目录下,与src、res是平级的关系)

(1)build.xml

(2)local.properties

(3)ant.properties

说明一下,这三个文件的关系,build.xml文件是最主要的文件,local.properties与ant.properties文件是build.xml中引用的文件,也就是一些变量的设置主要是在这两个文件当中设置。

源码分别如下:

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- 项目名称CreateApk,可用全局替换为当前项目名称 -->
<project
    name="CreateApk"
    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:/ant/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}/${ant.project.name}_${publish.date}_${channel}.apk" >
            <fileset
                dir="${out.absolute.dir}/"
                includes="${ant.project.name}-release.apk" />
        </copy>
 
        <delete includeEmptyDirs="true" >
            <fileset
                dir="${out.absolute.dir}"
                includes="**/*" />
        </delete>
 
        <echo message="=============生成完一个APK==============" />
    </target>
 
</project>


local.propertieslocal.properties

 

sdk.dir=d:/android-sdk-windows


ant.properties

application.package=com.test.createapk
ant.project.name=CreateApk
java.encoding=utf-8
out.absolute.dir=e:/apk/compile
gos.path=e:/apk/createapk
key.store=D:/keystore/key.keystore
key.store.password=hy123456
key.alias=china
key.alias.password=hy123456
app_version=1.0.0
market_channels=1001,1002
publish.date=2015-1-7


释意如下:

a、程序包名

b、项目名称

c、项目编码

d、临时文件存放位置

e、apk文件存放位置

f、秘钥所在位置

g、秘钥密码

h、秘钥别名

i、别名密码

j、版本

k、渠道名称,要以逗号分隔,必须在一行内

l、发布日期

 

6、运行与生成

     (1)检查自己配置的那些个目录在本地磁盘中是否已经创建好了文件夹

      (2)检查build.xml文件中设置与引用的文件(local.properties、ant.properties)是否准备好

       (3)右击build.xml文件——>run as ——> ant build

 

 

 

 

 

 

 

 

 

Android批量生成渠道包

标签:android   ant   

原文地址:http://blog.csdn.net/qinyunying/article/details/42489387

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!