標籤:
一、配置Ant環境變數
JAVA_HOME=/software/jdk1.6.0_24ANT_HOME=/software/apache-ant-1.9.2Android_Home=/software/android-sdk-linuxexport JAVA_HOME ANT_HOME Android_HomePATH=$JAVA_HOME/bin:$ANT_HOME/bin:$ANDROID_HOME/tools$Android_Home/tools/proguard/bin:$/software/decompile/dex2jar-0.0.9.13:$PATHexport PATHCLASSPATH=/software/apache-ant-1.9.2/libexport CLASSPATH
View Code
二、copy以下三個檔案到工程根目錄
檔案一:ant.propertiesout.absolute.dir=輸出apk目錄ant.project.name=工程名字gos.path=輸出mapping檔案等編譯相關目錄key.alias=alias名稱java.encoding=utf-8key.store.password=密碼application.package=cn.ibm.moa.android.cfkey.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批量打包