用于构建apk文件的ant脚本并将其加载到模拟器中?

时间:2010-07-19 08:57:01

标签: android ant scripting

我正在尝试创建一个build.xml脚本,用于清理,构建和创建我已创建的Junit android测试项目的apk文件。

我想在我的构建文件中实现的步骤是:

清洁

构建

创建apk文件

签署apk文件

启动模拟器

安装apk文件

运行instrumentalTest

将测试保存到HTML Junit报告

任何人都知道如何实现这一目标?到目前为止,我的构建文件如下所示:..

<!-- 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="Unity Agent SDK Test">
 <property environment="env" />
 <property name="junit.output.dir" value="junit" />
 <property name="debuglevel" value="source,lines,vars" />
 <property name="target" value="1.6" />
 <property name="source" value="1.6" />
 <property file="build.properties" />
 <path id="android1.6.userclasspath">
  <pathelement location="lib/android.jar" />
 </path>
 <path id="Junit.userclasspath">
  <pathelement location="lib/junit-4.8.2" />
  <pathelement location="lib/org.hamcrest.core_1.1.0.v20090501071000.jar" />
 </path>
 <path id="Unity Agent SDK Test.classpath">
  <pathelement location="bin" />
  <pathelement location="lib/fb_connect-android-api.jar" />
  <pathelement location="lib/signpost-commonshttp4-1.2.jar" />
  <pathelement location="lib/signpost-core-1.2.jar" />
  <pathelement location="lib/UnityAgentSDK.jar" />
  <path refid="android1.6.userclasspath" />
  <path refid="Junit.userclasspath" />
 </path>

 <path id="android.antlibs">
  <pathelement path="${android-sdk-path}/tools/lib/anttasks.jar" />
  <pathelement path="${android-sdk-path}/tools/lib/sdklib.jar" />
  <pathelement path="${android-sdk-path}/tools/lib/androidprefs.jar" />
  <pathelement path="${android-sdk-path}/tools/lib/apkbuilder.jar" />
  <pathelement path="${android-sdk-path}/tools/lib/jarutils.jar" />
 </path>

 <path id="run.Unity Agent SDK Test (1).classpath">
  <path refid="Unity Agent SDK Test.classpath" />
 </path>
 <path id="run.Unity Agent SDK Test (1).bootclasspath" />
 <target name="init">
  <echo message="Initialize project" />
  <mkdir dir="bin" />
  <copy includeemptydirs="false" todir="bin">
   <fileset dir="src">
    <exclude name="**/*.launch" />
    <exclude name="**/*.java" />
   </fileset>
  </copy>
  <copy includeemptydirs="false" todir="bin">
   <fileset dir="gen">
    <exclude name="**/*.launch" />
    <exclude name="**/*.java" />
   </fileset>
  </copy>
 </target>

 <target name="clean">
  <echo message="Cleaning project" />
  <delete dir="bin" />
 </target>
 <target depends="clean" name="cleanall" />
 <target depends="build-subprojects,build-project" name="build" />
 <target name="build-subprojects" />
 <target depends="init" name="build-project">
  <echo message="${ant.project.name}: ${ant.file}" />
  <javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
   <src path="src" />
   <classpath refid="Unity Agent SDK Test.classpath" />
  </javac>
  <javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
   <src path="gen" />
   <classpath refid="Unity Agent SDK Test.classpath" />
  </javac>
 </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" />
  </copy>
  <unzip dest="${ant.library.dir}">
   <patternset includes="jdtCompilerAdapter.jar" />
   <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar" />
  </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" />
 </target>
 <target name="Unity Agent SDK Test ">
  <mkdir dir="${junit.output.dir}" />
  <echo message="making directory" />
  <junit fork="yes" printsummary="yes">
   <formatter type="xml" />
   <test name="com.kc.AllTests" todir="${junit.output.dir}" />

   <!--
   <test name="com.kc.AllTests" todir="${junit.output.dir}" />

             <test name="com.kc.unity.agent.util.ActivityOneTestcase" todir="${junit.output.dir}" />
   <test name="com.kc.unity.agent.util.FaceBookRestManagerTestCase" todir="${junit.output.dir}" />
   <test name="com.kc.unity.agent.util.OAuthManagerTestCase" todir="${junit.output.dir}" /> 
-->

   <classpath refid="Unity Agent SDK Test.classpath" />

   <bootclasspath>
    <path refid="run.Unity Agent SDK Test (1).bootclasspath" />
   </bootclasspath>
  </junit>
  <echo message="junit finished" />
 </target>
 <target name="junitreport">
  <junitreport todir="${junit.output.dir}">
   <fileset dir="${junit.output.dir}">
    <include name="TEST-*.xml" />
   </fileset>
   <report format="frames" todir="${junit.output.dir}" />
  </junitreport>
 </target>

 <!--
 Build it and set it up for android
 -->
 <echo message="Build it and set it up for android" />
  <echo message="${android-sdk-path}" />
  <target name="push_tests_to_device"  depends="build">
   <exec executable="${android-sdk-path}/tools/adb.exe">
    <arg value="install"/>
    <arg value="${test_apk_path}"/>
   </exec>
  </target>

  <target name="run_tests"  depends="push_tests_to_device">
   <exec executable="${android-sdk-path}/tools/adb.exe">
    <arg value="shell"/>
    <arg value="am"/>
    <arg value="instrument"/>
    <arg value="-w"/>
    <arg value="com.kc.tests/android.test.InstrumentationTestRunner"/>
   </exec>
  </target>

</project>

我可以清理和构建项目,但不知道如何创建apk文件,签名,运行instrumentalTest并以html格式生成junit报告。

提前谢谢。这是我第一次潜入这里。我尝试使用eclipse&gt;自动生成build.xml。项目&gt;导出&gt; ant构建脚本,它不会添加apk构建,运行instrumenatlTest并在其中运行模拟器。

0 个答案:

没有答案