一、配置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
二、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=应用版本
文件二: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>
文件三:local.properties #sdk根目录 sdk.dir=/software/android-sdk-linux
三、在终端中切换到工程根目录下执行命令:ant deploy
打包成功后会显示以下提示
BUILD SUCCESSFUL
Total time: 1 minute 58 seconds
时间: 2024-10-01 08:00:00