为了可以实现自动化打包,下面我介绍一下如何用ant工具来打包android项目:
直接上build.xml文件源码:
<?xml version="1.0"?> <project name="WebGame" default="makeSuperJar" basedir="."> <property name="project.name" value="development"></property> <property name="build.dir" value="${basedir}/build"></property> <property name="classes" value="${basedir}/build/classes"/> <property name="dest" value="${basedir}/dest"/> <property name="src.dir" value="${basedir}"></property> <property name="assets" value="${basedir}/assets"></property> <property name="libs.dir" value="${basedir}/libs"></property> <property name="other.libs.dir" value="${basedir}/otherLibs"></property> <path id="project.libs.jar"> <fileset dir="${basedir}/libs"> <include name="**/*.jar"/> </fileset> <fileset dir="${basedir}/otherLibs"> <include name="android.jar"/> </fileset> </path> <target name="compiler" depends="version, clean, mkdir" description="编译所有java文件"> <echo message="开始编译所有java文件..."/> <javac destdir="${classes}" source="1.6" includeantruntime="false" encoding="UTF-8" debug="on"> <src path="${src.dir}"></src> <classpath refid="project.libs.jar"></classpath> </javac> <copy todir="${classes}"> <fileset dir="${src.dir}/src"> <include name="**/*.txt"/> <include name="**/*.xml"/> <include name="**/*.handlers" /> <include name="**/*.schemas" /> <include name="**/*.xsd"/> </fileset> </copy> <copy todir="${classes}/assets"> <fileset dir="${assets}"> <include name="**/*.apk"/> <include name="**/*.txt"/> <include name="**/*.xml"/> <include name="**/*.handlers" /> <include name="**/*.schemas" /> <include name="**/*.xsd"/> <include name="**/*.html"/> <include name="**/*"/> </fileset> </copy> <echo message="编译所有java文件成功!"/> </target> <target name="jar" depends="compiler" description="将class文件打成jar包"> <echo message="开始打jar包..."/> <jar destfile="${dest}/${project.name}.jar"> <fileset dir="${classes}"> <exclude name="**/*.bak"/> <exclude name="**/*.tmp"/> </fileset> </jar> <echo message="打jar包成功!"/> </target> <target name="mkdir"> <echo message="创建需要的文件夹..."/> <mkdir dir="${classes}"/> <mkdir dir="${dest}"/> <echo message="创建需要的文件夹成功!"/> </target> <target name="clean" description="初始化,并清除所有文件"> <echo message="初始化,并清除所有文件..."/> <delete dir="${basedir}/build"></delete> <delete dir="${dest}"></delete> <echo message="初始化,并清除所有文件成功!"/> </target> <target name="version" description="" if="ant.java.version"> <echo message="开始检查编译环境"/> <echo message="编译环境: java ${ant.java.version} ..."/> <echo message="检查编译环境成功!"/> </target> <target name="proguard" depends="jar"> <echo message="开始混淆jar包..."/> <taskdef resource="proguard/ant/task.properties" classpath="${other.libs.dir}/proguard.jar" /> <proguard configuration="${src.dir}/sdk.pro" /> <echo message="混淆jar包成功!"/> </target> <target name="makeSuperJar" depends="proguard" description="description"> <echo message="开始合并所有jar包"/> <jar destfile="${dest}/kkkWebGameAll.jar"> <zipfileset src="${libs.dir}/alipay_msp.jar"/> <zipfileset src="${libs.dir}/android-support-v4.jar"/> <zipfileset src="${libs.dir}/kkkwanMobileLog.jar"/> <zipfileset src="${libs.dir}/MobileProbe.jar"/> <zipfileset src="${libs.dir}/TenpayServiceSDK_V5.0.jar"/> <zipfileset src="${libs.dir}/UPPayAssistEx.jar"/> <zipfileset src="${libs.dir}/UPPayPluginEx.jar"/> <zipfileset src="${dest}/kkkwanWebGame.jar"/> </jar> <echo message="合并所有jar包成功!"/> </target> </project>
参考以上代码,然后适当修改成自己想需要的,就可以运行ant自动打包了!