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

Android Ant批量打包

时间:2015-01-13 12:19:11      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:

一、配置Ant环境变量

技术分享
JAVA_HOME=/software/jdk1.6.0_24
ANT_HOME=/software/apache-ant-1.9.2
Android_Home=/software/android-sdk-linux
export JAVA_HOME ANT_HOME Android_Home

PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$ANDROID_HOME/tools$Android_Home/tools/proguard/bin:$/software/decompile/dex2jar-0.0.9.13:$PATH
export PATH

CLASSPATH=/software/apache-ant-1.9.2/lib
export CLASSPATH
View Code

二、copy以下三个文件到工程根目录

技术分享
文件一:ant.properties
out.absolute.dir=输出apk目录
ant.project.name=工程名字
gos.path=输出mapping文件等编译相关目录
key.alias=alias名称
java.encoding=utf-8
key.store.password=密码
application.package=cn.ibm.moa.android.cf
key.store=keystore目录
key.alias.password=alias密码
market_channels=a01,a02,a03(渠道名,多渠道以逗号隔开)
app_version=应用版本
View Code
技术分享
文件二:build.xml(红色部分需要根据自己的情况修改)
<?xml version="1.0" encoding="UTF-8"?>
<project
    name="工程名"
    default="help" >

    <property file="local.properties" />

    <property file="ant.properties" />

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

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

        <classpath>
        <!-- ant目录下的lib -->
            <pathelement location="/software/apache-ant-1.9.2/lib/ant-contrib-1.0b3.jar" />
        </classpath>
    </taskdef>

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

    <import
        file="custom_rules.xml"
        optional="true" />

    <target name="clean_bin_gen" >

        <echo>
Cleaning the project...
        </echo>

        <delete dir="${report.dir}" />

        <delete dir="${build.dir}" />

        <delete
            includeemptydirs="true"
            verbose="true" >

            <fileset
                dir="bin"
                includes="**/*" >
            </fileset>
        </delete>

        <delete
            includeemptydirs="true"
            verbose="true" >

            <fileset
                dir="gen"
                includes="**/*" >
            </fileset>
        </delete>
    </target>

    <target
        name="deploy"
        depends="clean" >

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

    <target name="modify_manifest" >

        <replaceregexp byline="false" >

            <regexp pattern="android:debuggable="(.*)"" />

            <substitution expression="" />

            <fileset
                dir=""
                includes="AndroidManifest.xml" />
        </replaceregexp>

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

            <regexp pattern="android:name="APP_CHANNEL" *(\r\n)? *android:value="(.*)"" />

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

            <fileset
                dir=""
                includes="AndroidManifest.xml" />
        </replaceregexp>

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

            <regexp pattern="android:name="APP_CHANNEL01" *(\r\n)? *android:value="(.*)"" />

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

            <fileset
                dir=""
                includes="AndroidManifest.xml" />
        </replaceregexp>

        <antcall target="release" />

        <copy tofile="${gos.path}/应用名称_${channel}.apk" >

            <fileset
                dir="${out.absolute.dir}/"
                includes="应用名称-release.apk" />
        </copy>

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

</project>
View Code
技术分享
文件三:local.properties
#sdk根目录
sdk.dir=/software/android-sdk-linux
View Code

三、在终端中切换到工程根目录下执行命令:ant deploy  

打包成功后会显示以下提示

BUILD SUCCESSFUL
Total time: 1 minute 58 seconds

  

 

Android Ant批量打包

标签:

原文地址:http://www.cnblogs.com/zgz345/p/4220733.html

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