from:http://www.cnitblog.com/reene/archive/2011/06/30/74504.html

1. emma taskdef<!--Emmaconfiguration-->

< property name ="emma.dir" value ="${android.sdk.root}/tools/lib" />
< path id ="emma.lib.dir" >
< pathelement location ="${emma.dir}/emma.jar" />
< pathelement location ="${emma.dir}/emma_ant.jar" />
</ path >
< taskdef resource ="emma_ant.properties" classpathref ="emma.lib.dir" />
<!-- Endofemmaconfiguration -->
2. <!------------------- target:emma-instrument
-----------------
-->
< target name ="emma.instrument" if ="enable.emma.on.test" >
< property name ="emma.enabled" value ="true" />
< echo >Instrumentingclassesfrom${project.base.dir}/${android.project.dir}/bin,${project.base.dir}/${android.project.dir}/libs/sup-client.jar </ echo >
<!-- Itonlyinstrumentsclassfiles,notanyexternallibs -->
< emma enabled ="${emma.enabled}" >
< instr mode ="overwrite"
instrpath
="${project.base.dir}/${android.project.dir}/bin,${project.base.dir}/${android.project.dir}/libs/sup-client.jar"
outdir
="${project.base.dir}/${android.project.dir}/bin" >
</ instr >
<!-- TODO:exclusionfiltersonR*.classandallowingcustomexclusionfrom
userdefinedfile
-->
</ emma >
< echo >Copyemma.toprojectlibs </ echo >
< copy todir ="${project.base.dir}/${android.project.dir}/libs" overwrite ="true" >
< fileset dir ="${emma.dir}" includes ="emma_device.jar" />
</ copy >

</ target >
3
<!-- Convertthisproject's.classfilesinto.dexfiles. -->
< target name ="dex" depends ="android-javac" >
< antcall target ="emma.instrument" ></ antcall >
< condition property ="dx.extra.args" value ="--no-locals" else ="" >
< istrue value ="${enable.emma.on.test}" />
</ condition >
< echo >Convertingcompiledfilesandexternallibrariesintodexfile </ echo >
< apply executable ="${dx}" failonerror ="true" parallel ="true" >
< arg value ="--dex" />
< arg value ="${dx.extra.args}" />
< arg value ="--output=${project.base.dir}/${android.project.dir}/bin/classes.dex" />
< arg path ="${project.base.dir}/${android.project.dir}/bin" />
< fileset dir ="${project.base.dir}/${android.project.dir}/libs" >
< include name ="**/*.jar" />
</ fileset >
</ apply >
</ target >

4

< target name ="run-tests"
description
="Runstestsfromthepackagedefinedintest.packageproperty" >
< property name ="reports.dir" value ="${reports.out.dir}/reports" />
< property name ="device.reports.dir" value ="/data/data/${manifest.package}/files/reports/" />
< echo >Runningtests </ echo >
< exec executable ="${adb}" failonerror ="true" >
< arg value ="shell" />
< arg value ="am" />
< arg value ="instrument" />
< arg value ="-w" />
< arg value ="-e" />
< arg value ="coverage" />
< arg value ="true" />
< arg value ="-e" />
< arg value ="coverageFile" />
< arg value ="${device.reports.dir}coverage.ec" />
< arg value ="-e" />
< arg value ="junitOutputDirectory" />
< arg value ="${device.reports.dir}" />
< arg value ="-e" />
< arg value ="junitSplitLevel" />
< arg value ="class" />
< arg value ="-e" />
< arg value ="package" />
< arg value ="${test.target.package}" />
< arg value ="${manifest.package}/${test.runner}" />
</ exec >

< echo >DownloadingXMLtestreports </ echo >
< mkdir dir ="${reports.dir}" />
< exec executable ="${adb}" failonerror ="true" >
< arg value ="pull" />
< arg value ="${device.reports.dir}/" />
< arg value ="${reports.dir}" />
</ exec >
< exec executable ="${adb}" failonerror ="true" >
< arg value ="pull" />
< arg value ="${device.reports.dir}/" />
< arg value ="${reports.dir}" />
</ exec >
</ target >
5

< antcall target ="reinstall" >
< param name ="android.project.dir" value ="end2end_rdb_mbs" />
< param name ="android.app.name" value ="end2end_rdb_mbs" />
< param name ="project.base.dir" value ="${project.home}/android_mbs" />
< param name ="enable.emma.on.test" value ="true" />
</ antcall >
6

< antcall target ="run-tests" >
< param name ="android.project.dir" value ="end2end_rdb_mbs" />
< param name ="android.app.name" value ="end2end_rdb_mbs" />
< param name ="project.base.dir" value ="${project.home}/android_mbs" />
< param name ="manifest.package" value ="end2end.test" />
< param name ="test.target.package" value ="end2end.test.rest.mbs.android" />
< param name ="test.runner" value ="pl.polidea.instrumentation.PolideaInstrumentationTestRunner" />
< param name ="enable.emma.on.test" value ="true" />
</ antcall >

--------------------------------------------转载结束线-------------------------------

如果不想独立弄一个build.xml,可以借助android工具,先将工程转换成ant工程。然后,修改android sdk下/ant/build.xml中的脚本,这样也能很方便的实现支持emma,不过,这样是否能够顺畅地脱离IDE来运行ant脚本,这个没有试验。此思路仅供参考。

更多相关文章

  1. IDEA 13 编译android工程出现java.nio.BufferOverflowException
  2. Android Library Project 的使用小结以及脚本打包事项
  3. android 应用 Ant脚本自动编译、打包、代码混淆、签名、安装等
  4. Android 技术目标:全栈工程师
  5. android工程下不能运行java main程序的解决办法
  6. Android之路——走进Android(工程结构剖析)
  7. Android学习路线:如何成长为高级工程师

随机推荐

  1. Android(安卓)API中文文档Button
  2. 去掉RecycleView或者ListView上下滑动阴
  3. Android(安卓)TextView 设置行间距字间距
  4. 【原创】Proton在Android上的编译
  5. Android(安卓)Studio系列(四)Version Contr
  6. 相对布局属性
  7. android 去掉顶部状态栏
  8. Android简明开发教程二十二:使用资源Resou
  9. Android(安卓)9.0 Launcher源码分析(三)—
  10. Android(安卓)修改程序字体