私はこの質問と同じ問題を抱えています: Android unit test using ant with library project
質問で提案された両方の方法を試しましたが、Android ツールの r18 リリースでは、次のようになっています。
NTServicesTest/build.xml:110: Reference jar.libs.ref not found.
元の質問への回答の回避策のレシピに従うことに失敗したのは私なのか、それとも Android ツールの r18 で何かが変更されたのかはわかりません。
私のフォルダー設定は、.. を含む proj フォルダーにあります。
NTServices 、 NTServicesTest 、 NTServicesTestApp
@Snicolas の回避策として、NTServicesTest/project.properties を次のように変更しました。
# Project target.
target=android-15
tested.android.library.reference.1=../NTServices
そして、私の NTServicesTest/build.xml は次のようになります: (バージョンタグのすぐ下から)
<import file="${sdk.dir}/tools/ant/build.xml" />
<!-- override "compile" target in platform android_rules.xml to include tested app's external libraries -->
<!-- Compiles this project's .java files into .class files. -->
<target name="-compile" depends="-build-setup, -pre-build, -code-gen, -pre-compile">
<do-only-if-manifest-hasCode elseText="hasCode = false. Skipping...">
<!-- If android rules are used for a test project, its classpath should include
tested project's location -->
<condition property="extensible.classpath"
value="${tested.project.absolute.dir}/bin/classes"
else=".">
<isset property="tested.project.absolute.dir" />
</condition>
<condition property="extensible.libs.classpath"
value="${tested.project.absolute.dir}/${jar.libs.dir}"
else="${jar.libs.dir}">
<isset property="tested.project.absolute.dir" />
</condition>
<echo message="jar libs dir : ${tested.project.target.project.libraries.jars}"/>
<javac encoding="${java.encoding}"
source="${java.source}" target="${java.target}"
debug="true" extdirs="" includeantruntime="false"
destdir="${out.classes.absolute.dir}"
bootclasspathref="android.target.classpath"
verbose="${verbose}"
classpath="${extensible.classpath}"
classpathref="jar.libs.ref">
<src path="${source.absolute.dir}" />
<src path="${gen.absolute.dir}" />
<classpath>
<!-- steff: we changed one line here !-->
<fileset dir="${tested.android.library.reference.1}/bin/" includes="*.jar"/>
<fileset dir="${extensible.libs.classpath}" includes="*.jar" />
</classpath>
<compilerarg line="${java.compilerargs}" />
</javac>
<!-- if the project is instrumented, intrument the classes -->
<if condition="${build.is.instrumented}">
<then>
<echo>Instrumenting classes from ${out.absolute.dir}/classes...</echo>
<!-- It only instruments class files, not any external libs -->
<emma enabled="true">
<instr verbosity="${verbosity}"
mode="overwrite"
instrpath="${out.absolute.dir}/classes"
outdir="${out.absolute.dir}/classes">
</instr>
<!-- TODO: exclusion filters on R*.class and allowing custom exclusion from
user defined file -->
</emma>
</then>
</if>
</do-only-if-manifest-hasCode>
</target>