robotium测试工程打包与签名,可以用ant实现,使用ant前,需要创建build.xml文件。
robotium测试工程的打包与普通android工程的不同点在于,构建robotium测试工程前需要先构建android被测工程。
用eclipse导出的build.xml如下:
- <?xml version="1.0" encoding="UTF-8" standalone="no"?>
- <!-- WARNING: Eclipse auto-generated file.
- Any modifications will be overwritten.
- To include a user specific buildfile here, simply create one in the same
- directory with the processing instruction <?eclipse.ant.import?>
- as the first entry and export the buildfile again. -->
- <project basedir="." default="build" name="RobotiumTest">
- <property environment="env">
- <property name="ECLIPSE_HOME" value="../../eclipse">
- <property name="ExampleProject.location" value="../../eclipse/workspace/ExampleProject">
- <property name="debuglevel" value="source,lines,vars">
- <property name="target" value="1.6">
- <property name="source" value="1.6">
- <path id="Android 4.0.libraryclasspath">
- <pathelement location="../../android-sdk-windows/platforms/android-14/android.jar">
- </pathelement></path>
- <path id="Android Dependencies.libraryclasspath">
- <pathelement location="../../android-sdk-windows/tools/support/annotations.jar">
- <pathelement location="libs/all.jar">
- <pathelement location="libs/robotium-solo-4.1.jar">
- </pathelement></pathelement></pathelement></path>
- <path id="ExampleProject.classpath">
- <path refid="Android 4.0.libraryclasspath">
- <path refid="Android Dependencies.libraryclasspath">
- <pathelement location="${ExampleProject.location}/bin/classes">
- <pathelement location="${ExampleProject.location}/libs/android-support-v4.jar">
- </pathelement></pathelement></path>
- <path id="RobotiumTest.classpath">
- <pathelement location="bin/classes">
- <path refid="Android 4.0.libraryclasspath">
- <pathelement location="Robotium/robotium-solo-4.1.jar">
- <path refid="Android Dependencies.libraryclasspath">
- <path refid="ExampleProject.classpath">
- </path>
- <target name="init">
- <mkdir dir="bin/classes">
- <copy includeemptydirs="false" todir="bin/classes">
- <fileset dir="gen">
- <exclude name="**/*.java">
- </exclude></fileset>
- </copy>
- <copy includeemptydirs="false" todir="bin/classes">
- <fileset dir="src">
- <exclude name="**/*.java">
- </exclude></fileset>
- </copy>
- </mkdir></target>
- <target name="clean">
- <delete dir="bin/classes">
- </delete></target>
- <target depends="clean" name="cleanall">
- <ant antfile="build.xml" dir="${ExampleProject.location}" inheritall="false" target="clean">
- </ant></target>
- <target depends="build-subprojects,build-project" name="build">
- <target name="build-subprojects">
- <ant antfile="build.xml" dir="${ExampleProject.location}" inheritall="false" target="build-project">
- <propertyset>
- <propertyref name="build.compiler">
- </propertyref></propertyset>
- </ant>
- </target>
- <target depends="init" name="build-project">
- <echo message="${ant.project.name}: ${ant.file}">
- <javac debug="true" debuglevel="${debuglevel}" destdir="bin/classes" source="${source}" target="${target}">
- <src path="gen">
- <classpath refid="RobotiumTest.classpath">
- </classpath></src></javac>
- <javac debug="true" debuglevel="${debuglevel}" destdir="bin/classes" source="${source}" target="${target}">
- <src path="src">
- <classpath refid="RobotiumTest.classpath">
- </classpath></src></javac>
- </echo></target>
- <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects">
- <target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
- <copy todir="${ant.library.dir}">
- <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar">
- </fileset></copy>
- <unzip dest="${ant.library.dir}">
- <patternset includes="jdtCompilerAdapter.jar">
- <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar">
- </fileset></patternset></unzip>
- </target>
- <target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
- <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter">
- <antcall target="build">
- </project>
自动导出的这个文件普通构建是可以的,但并没有完成打包签名,更无法完成更加智能些的自动化,需要根据情况作出修改。
build.xml文件中主要标签:
1.property,用于定义变量,如<property name="ECLIPSE_HOME" value="../../eclipse"/>,相当于ECLIPSE_HOME=../../eclipse,之后就可以引用这个变量了。
2.path,定义编译文件时所引用的库,<path id="Android 4.0.libraryclasspath">
3.target,定义任务,如<target name="init">,ant就是根据一个个任务执行命令的。
4.depends,定义任务之前的依赖关系,如<target depends="init" name="build-project">,当执行任务build-project时会先执行depends中的任务。
android工程打包签名的一般步骤:
一、打包资源文件,生成R.java文件
【输入】Resource文件(工程中res中的文件)、Assets文件(另外一种资源)、AndroidManifest.xml文件、Android基础类库(Android.jar文件)
【输出】打包好的资源(Android工程的bin目录resources.ap_)、R.java文件(gen目录中)
【工具】aapt工具,路径${ANDROID_SDK_HOME}/platform-tools/aapt
二、处理AIDL文件,生成对应的.java文件(没有用到AIDL,这个过程就可以省了)
【输入】源码文件、aidl文件、framework.aidl文件
【输出】对应的.java文件
【工具】aidl工具
三、编译Java文件,生成对应的.class文件
【输入】源码文件(包括R.java和AIDL生成的.java文件)、库文件(.jar文件)
【输出】.class文件
【工具】javac工具
四、把.class文件转化成Davik VM支持的.dex文件
【输入】 .class文件(包括Aidl生成.class文件,R生成的.class文件,源文件生成的.class文件),库文件(.jar文件)
【输出】.dex文件
【工具】javac工具
五、打包生成未签名的.apk文件
【输入】打包后的资源文件、打包后类文件(.dex文件)、libs文件(包括.so文件)
【输出】未签名的.apk文件
【工具】apkbuilder工具
六、对未签名.apk文件进行签名
【输入】未签名的.apk文件
【输出】签名的.apk文件
【工具】jarsigner
七、对签名后的.apk文件进行对齐处理(不进行对齐处理不能发布到Google Market)
【输入】签名后的.apk文件
【输出】对齐后的.apk文件
【工具】zipalign工具
了解了一般打包签名步骤后,就可以根据需要修改build.xml文件了
不使用从eclipse导出的build文件,这样便于脱离IDE环境,减少依赖,更有利于持续集成
|