MyAppというアプリを構築するモジュールがあります。 MyAppTestsと呼ばれる、そのアプリのテストケースを作成する別のアプリがあります。どちらも独自のAPKを構築し、どちらも私のIDE内から正常に動作します。継続的インテグレーションを利用できるように、antを使用してそれらを構築したいと思います。
アプリモジュールのビルドは正常に機能します。 Testモジュールをコンパイルして実行するのに苦労しています。
前の質問 からのクリストファーのヒントを使用して、Android create test-project -p MyAppTests -m ../MyApp -n MyAppTests
を使用して、テストプロジェクトをビルドおよび実行するために必要なビルドファイルを作成しました。これはうまく機能しているようです(作成した不要なテストケースを削除し、AndroidManifest.xmlをAndroid create
に置き換える前に使用していたものに戻します)。ただし、2つの問題があります。
最初の問題:ライブラリがないため、プロジェクトがコンパイルされない。
$ ant run-tests
Buildfile: build.xml
[setup] Project Target: Google APIs
[setup] Vendor: Google Inc.
[setup] Platform Version: 1.6
[setup] API level: 4
[setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.
-install-tested-project:
[setup] Project Target: Google APIs
[setup] Vendor: Google Inc.
[setup] Platform Version: 1.6
[setup] API level: 4
[setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.
-compile-tested-if-test:
-dirs:
[echo] Creating output directories if needed...
-resource-src:
[echo] Generating R.Java / Manifest.Java from the resources...
-aidl:
[echo] Compiling aidl files into Java classes...
compile:
[javac] Compiling 1 source file to /Users/mike/Projects/myapp/Android/MyApp/bin/classes
-dex:
[echo] Converting compiled files and external libraries into /Users/mike/Projects/myapp/Android/MyApp/bin/classes.dex...
[echo]
-package-resources:
[echo] Packaging resources
[aaptexec] Creating full resource package...
-package-debug-sign:
[apkbuilder] Creating MyApp-debug-unaligned.apk and signing it with a debug key...
[apkbuilder] Using keystore: /Users/mike/.Android/debug.keystore
debug:
[echo] Running Zip align on final apk...
[echo] Debug Package: /Users/mike/Projects/myapp/Android/MyApp/bin/MyApp-debug.apk
install:
[echo] Installing /Users/mike/Projects/myapp/Android/MyApp/bin/MyApp-debug.apk onto default emulator or device...
[exec] 1567 KB/s (288354 bytes in 0.179s)
[exec] pkg: /data/local/tmp/MyApp-debug.apk
[exec] Success
-compile-tested-if-test:
-dirs:
[echo] Creating output directories if needed...
[mkdir] Created dir: /Users/mike/Projects/myapp/Android/MyAppTests/gen
[mkdir] Created dir: /Users/mike/Projects/myapp/Android/MyAppTests/bin
[mkdir] Created dir: /Users/mike/Projects/myapp/Android/MyAppTests/bin/classes
-resource-src:
[echo] Generating R.Java / Manifest.Java from the resources...
-aidl:
[echo] Compiling aidl files into Java classes...
compile:
[javac] Compiling 5 source files to /Users/mike/Projects/myapp/Android/MyAppTests/bin/classes
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/GsonTest.Java:4: package roboguice.test does not exist
[javac] import roboguice.test.RoboUnitTestCase;
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/GsonTest.Java:8: package com.google.gson does not exist
[javac] import com.google.gson.JsonElement;
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/GsonTest.Java:9: package com.google.gson does not exist
[javac] import com.google.gson.JsonParser;
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/GsonTest.Java:11: cannot find symbol
[javac] symbol: class RoboUnitTestCase
[javac] public class GsonTest extends RoboUnitTestCase<MyApplication> {
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/HttpTest.Java:6: package roboguice.test does not exist
[javac] import roboguice.test.RoboUnitTestCase;
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/HttpTest.Java:7: package roboguice.util does not exist
[javac] import roboguice.util.RoboLooperThread;
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/HttpTest.Java:11: package com.google.gson does not exist
[javac] import com.google.gson.JsonObject;
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/HttpTest.Java:15: cannot find symbol
[javac] symbol: class RoboUnitTestCase
[javac] public class HttpTest extends RoboUnitTestCase<MyApplication> {
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/LinksTest.Java:4: package roboguice.test does not exist
[javac] import roboguice.test.RoboUnitTestCase;
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/LinksTest.Java:12: cannot find symbol
[javac] symbol: class RoboUnitTestCase
[javac] public class LinksTest extends RoboUnitTestCase<MyApplication> {
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/SafeAsyncTest.Java:4: package roboguice.test does not exist
[javac] import roboguice.test.RoboUnitTestCase;
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/SafeAsyncTest.Java:5: package roboguice.util does not exist
[javac] import roboguice.util.RoboAsyncTask;
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/SafeAsyncTest.Java:6: package roboguice.util does not exist
[javac] import roboguice.util.RoboLooperThread;
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/SafeAsyncTest.Java:12: cannot find symbol
[javac] symbol: class RoboUnitTestCase
[javac] public class SafeAsyncTest extends RoboUnitTestCase<MyApplication> {
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyApp/bin/classes/com/myapp/activity/Stories.class: warning: Cannot find annotation method 'value()' in type 'roboguice.inject.InjectResource': class file for roboguice.inject.InjectResource not found
[javac] /Users/mike/Projects/myapp/Android/MyApp/bin/classes/com/myapp/activity/Stories.class: warning: Cannot find annotation method 'value()' in type 'roboguice.inject.InjectResource'
[javac] /Users/mike/Projects/myapp/Android/MyApp/bin/classes/com/myapp/activity/Stories.class: warning: Cannot find annotation method 'value()' in type 'roboguice.inject.InjectView': class file for roboguice.inject.InjectView not found
[javac] /Users/mike/Projects/myapp/Android/MyApp/bin/classes/com/myapp/activity/Stories.class: warning: Cannot find annotation method 'value()' in type 'roboguice.inject.InjectView'
[javac] /Users/mike/Projects/myapp/Android/MyApp/bin/classes/com/myapp/activity/Stories.class: warning: Cannot find annotation method 'value()' in type 'roboguice.inject.InjectView'
[javac] /Users/mike/Projects/myapp/Android/MyApp/bin/classes/com/myapp/activity/Stories.class: warning: Cannot find annotation method 'value()' in type 'roboguice.inject.InjectView'
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/GsonTest.Java:15: cannot find symbol
[javac] symbol : class JsonParser
[javac] location: class com.myapp.test.GsonTest
[javac] final JsonParser parser = new JsonParser();
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/GsonTest.Java:15: cannot find symbol
[javac] symbol : class JsonParser
[javac] location: class com.myapp.test.GsonTest
[javac] final JsonParser parser = new JsonParser();
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/GsonTest.Java:18: cannot find symbol
[javac] symbol : class JsonElement
[javac] location: class com.myapp.test.GsonTest
[javac] final JsonElement e = parser.parse(s);
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/GsonTest.Java:20: cannot find symbol
[javac] symbol : class JsonElement
[javac] location: class com.myapp.test.GsonTest
[javac] final JsonElement e2 = parser.parse(s2);
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/HttpTest.Java:19: cannot find symbol
[javac] symbol : method getInstrumentation()
[javac] location: class com.myapp.test.HttpTest
[javac] assertEquals("MyApp", getInstrumentation().getTargetContext().getResources().getString(com.myapp.R.string.app_name));
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/HttpTest.Java:62: cannot find symbol
[javac] symbol : class RoboLooperThread
[javac] location: class com.myapp.test.HttpTest
[javac] new RoboLooperThread() {
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/HttpTest.Java:82: cannot find symbol
[javac] symbol : method assertTrue(Java.lang.String,boolean)
[javac] location: class com.myapp.test.HttpTest
[javac] assertTrue(result[0], result[0].contains("Search"));
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/HttpTest.Java:87: cannot find symbol
[javac] symbol : class JsonObject
[javac] location: class com.myapp.test.HttpTest
[javac] final JsonObject[] result = {null};
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/HttpTest.Java:90: cannot find symbol
[javac] symbol : class RoboLooperThread
[javac] location: class com.myapp.test.HttpTest
[javac] new RoboLooperThread() {
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/HttpTest.Java:117: cannot find symbol
[javac] symbol : class JsonObject
[javac] location: class com.myapp.test.HttpTest
[javac] final JsonObject[] result = {null};
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/HttpTest.Java:120: cannot find symbol
[javac] symbol : class RoboLooperThread
[javac] location: class com.myapp.test.HttpTest
[javac] new RoboLooperThread() {
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/LinksTest.Java:27: cannot find symbol
[javac] symbol : method assertTrue(boolean)
[javac] location: class com.myapp.test.LinksTest
[javac] assertTrue(m.matches());
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/LinksTest.Java:28: cannot find symbol
[javac] symbol : method assertEquals(Java.lang.String,Java.lang.String)
[javac] location: class com.myapp.test.LinksTest
[javac] assertEquals( map.get(url), m.group(1) );
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/SafeAsyncTest.Java:19: cannot find symbol
[javac] symbol : method getInstrumentation()
[javac] location: class com.myapp.test.SafeAsyncTest
[javac] assertEquals("MyApp", getInstrumentation().getTargetContext().getString(com.myapp.R.string.app_name));
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/SafeAsyncTest.Java:27: cannot find symbol
[javac] symbol : class RoboLooperThread
[javac] location: class com.myapp.test.SafeAsyncTest
[javac] new RoboLooperThread() {
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/SafeAsyncTest.Java:65: cannot find symbol
[javac] symbol : method assertEquals(com.myapp.test.SafeAsyncTest.State,com.myapp.test.SafeAsyncTest.State)
[javac] location: class com.myapp.test.SafeAsyncTest
[javac] assertEquals(State.TEST_SUCCESS,state[0]);
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/SafeAsyncTest.Java:74: cannot find symbol
[javac] symbol : class RoboLooperThread
[javac] location: class com.myapp.test.SafeAsyncTest
[javac] new RoboLooperThread() {
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/SafeAsyncTest.Java:105: cannot find symbol
[javac] symbol : method assertEquals(com.myapp.test.SafeAsyncTest.State,com.myapp.test.SafeAsyncTest.State)
[javac] location: class com.myapp.test.SafeAsyncTest
[javac] assertEquals(State.TEST_SUCCESS,state[0]);
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/SafeAsyncTest.Java:113: cannot find symbol
[javac] symbol : class RoboLooperThread
[javac] location: class com.myapp.test.SafeAsyncTest
[javac] new RoboLooperThread() {
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/SafeAsyncTest.Java:144: cannot find symbol
[javac] symbol : method assertEquals(com.myapp.test.SafeAsyncTest.State,com.myapp.test.SafeAsyncTest.State)
[javac] location: class com.myapp.test.SafeAsyncTest
[javac] assertEquals(State.TEST_SUCCESS,state[0]);
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/SafeAsyncTest.Java:154: cannot find symbol
[javac] symbol : class RoboLooperThread
[javac] location: class com.myapp.test.SafeAsyncTest
[javac] new RoboLooperThread() {
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/SafeAsyncTest.Java:187: cannot find symbol
[javac] symbol : method assertEquals(com.myapp.test.SafeAsyncTest.State,com.myapp.test.SafeAsyncTest.State)
[javac] location: class com.myapp.test.SafeAsyncTest
[javac] assertEquals(State.TEST_SUCCESS,state[0]);
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/StoriesTest.Java:11: cannot access roboguice.activity.GuiceListActivity
[javac] class file for roboguice.activity.GuiceListActivity not found
[javac] public class StoriesTest extends ActivityUnitTestCase<Stories> {
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/StoriesTest.Java:21: cannot access roboguice.application.GuiceApplication
[javac] class file for roboguice.application.GuiceApplication not found
[javac] setApplication( new MyApplication( getInstrumentation().getTargetContext() ) );
[javac] ^
[javac] /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/StoriesTest.Java:22: incompatible types
[javac] found : com.myapp.activity.Stories
[javac] required: Android.app.Activity
[javac] final Activity activity = startActivity(intent, null, null);
[javac] ^
[javac] 39 errors
[javac] 6 warnings
BUILD FAILED
/opt/local/Android-sdk-mac/platforms/Android-1.6/templates/Android_rules.xml:248: Compile failed; see the compiler error output for details.
Total time: 24 seconds
それは解決するのが難しい問題ではありません。それが正しいことかどうかはわかりませんが、不足しているライブラリ(roboguiceとgson)をMyApp/libsディレクトリからMyAppTests/libsディレクトリにコピーしましたが、すべて正常にコンパイルされているようです。
しかし、それが原因で2つ目の問題が発生します。テストは問題なくコンパイルされますが、実行されません。
$ cp ../MyApp/libs/gson-r538.jar libs/
$ cp ../MyApp/libs/roboguice-1.1-SNAPSHOT.jar libs/
0 10:23 /Users/mike/Projects/myapp/Android/MyAppTests $ ant run-testsBuildfile: build.xml
[setup] Project Target: Google APIs
[setup] Vendor: Google Inc.
[setup] Platform Version: 1.6
[setup] API level: 4
[setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.
-install-tested-project:
[setup] Project Target: Google APIs
[setup] Vendor: Google Inc.
[setup] Platform Version: 1.6
[setup] API level: 4
[setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.
-compile-tested-if-test:
-dirs:
[echo] Creating output directories if needed...
-resource-src:
[echo] Generating R.Java / Manifest.Java from the resources...
-aidl:
[echo] Compiling aidl files into Java classes...
compile:
[javac] Compiling 1 source file to /Users/mike/Projects/myapp/Android/MyApp/bin/classes
-dex:
[echo] Converting compiled files and external libraries into /Users/mike/Projects/myapp/Android/MyApp/bin/classes.dex...
[echo]
-package-resources:
[echo] Packaging resources
[aaptexec] Creating full resource package...
-package-debug-sign:
[apkbuilder] Creating MyApp-debug-unaligned.apk and signing it with a debug key...
[apkbuilder] Using keystore: /Users/mike/.Android/debug.keystore
debug:
[echo] Running Zip align on final apk...
[echo] Debug Package: /Users/mike/Projects/myapp/Android/MyApp/bin/MyApp-debug.apk
install:
[echo] Installing /Users/mike/Projects/myapp/Android/MyApp/bin/MyApp-debug.apk onto default emulator or device...
[exec] 1396 KB/s (288354 bytes in 0.201s)
[exec] pkg: /data/local/tmp/MyApp-debug.apk
[exec] Success
-compile-tested-if-test:
-dirs:
[echo] Creating output directories if needed...
-resource-src:
[echo] Generating R.Java / Manifest.Java from the resources...
-aidl:
[echo] Compiling aidl files into Java classes...
compile:
[javac] Compiling 5 source files to /Users/mike/Projects/myapp/Android/MyAppTests/bin/classes
[javac] Note: /Users/mike/Projects/myapp/Android/MyAppTests/src/com/myapp/test/SafeAsyncTest.Java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
-dex:
[echo] Converting compiled files and external libraries into /Users/mike/Projects/myapp/Android/MyAppTests/bin/classes.dex...
[echo]
-package-resources:
[echo] Packaging resources
[aaptexec] Creating full resource package...
-package-debug-sign:
[apkbuilder] Creating MyAppTests-debug-unaligned.apk and signing it with a debug key...
[apkbuilder] Using keystore: /Users/mike/.Android/debug.keystore
debug:
[echo] Running Zip align on final apk...
[echo] Debug Package: /Users/mike/Projects/myapp/Android/MyAppTests/bin/MyAppTests-debug.apk
install:
[echo] Installing /Users/mike/Projects/myapp/Android/MyAppTests/bin/MyAppTests-debug.apk onto default emulator or device...
[exec] 1227 KB/s (94595 bytes in 0.075s)
[exec] pkg: /data/local/tmp/MyAppTests-debug.apk
[exec] Success
run-tests:
[echo] Running tests ...
[exec]
[exec] Android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests:INSTRUMENTATION_RESULT: shortMsg=Class ref in pre-verified class resolved to unexpected implementation
[exec] INSTRUMENTATION_RESULT: longMsg=Java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
[exec] INSTRUMENTATION_CODE: 0
BUILD SUCCESSFUL
Total time: 38 seconds
「事前検証済みクラスのクラス参照が予期しない実装に解決された」というエラーの原因は何ですか?
問題は、Android antビルドスクリプトにバグがあり、テスタープロジェクトのコンパイル時にテスト済みプロジェクトのlibsディレクトリが含まれていないことです。ライブラリをにコピーして回避しようとすると、テスタープロジェクトのlibsディレクトリでは、faddenが指摘したように、実行時にクラス検証の問題が発生します。
解決策は、元々AndroidのAndroid_test_rules.xml
にあるcompile
ターゲットを調整して、<fileset dir="${tested.project.absolute.dir}/libs" includes="*.jar" />
を<classpath>
ディレクティブに追加することです。
改訂されたcompile
ターゲットは次のとおりです。 TESTERプロジェクトのbuild.xmlに追加することで、Android_test_rules.xmlのそれよりも優先されます。
<!-- override "compile" target in platform Android_rules.xml to include tested app's external libraries -->
<target name="compile" depends="-resource-src, -aidl"
description="Compiles project's .Java files into .class files">
<!-- 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>
<javac encoding="ascii" target="1.5" debug="true" extdirs=""
destdir="${out.classes.absolute.dir}"
bootclasspathref="Android.target.classpath"
verbose="${verbose}" classpath="${extensible.classpath}">
<src path="${source.absolute.dir}" />
<src path="${gen.absolute.dir}" />
<classpath>
<fileset dir="${tested.project.absolute.dir}/libs" includes="*.jar" />
<fileset dir="${external.libs.absolute.dir}" includes="*.jar" />
</classpath>
</javac>
</target>
Eclipseを使用する場合、より簡単な方法は、外部ライブラリをテストプロジェクトに含めず、Eclipseプロジェクト設定でエクスポートすることです。これは問題を解決します
以前、私はこれを説明するブログ投稿を書きました: http://juristr.com/blog/2010/06/Android-instrumentation-test/
Intellij IDEA(11.1.1)を使用して同様の問題が発生しました。アプリが問題なくデバイスにビルドおよびデプロイされ、テストアプリが大量のdexエラーを発生させました。それを実行するには:「事前検証済みクラスのクラス参照が予期しない実装に解決されました」...
app test-app common-libs appはcommon-libsに依存します(そしてcommon-libsをエクスポートします) test-appはapp に依存しています
この投稿は、問題がアプリとテストアプリの.dexファイルの重複したクラスファイルであることを理解するのに役立ちました。 app-classをtest-appから除外するには、test-appのモジュール設定で、その依存関係appのスコープを「compile」から「provided」に変更する必要があることがわかりました。
上記のテキストには実際のエラーメッセージは表示されませんが、回答できると思います。
通常、警告は2つの異なるAPKに同じコードが表示されるために発生します。 1つのAPKの実装は事前検証と最適化に使用されましたが、他の実装は実行中に使用されています。 VMは、状況を検出し、クラスを拒否します。これは、検証と最適化が、もはや真ではない一連の仮定で実行されたためです。
これを修正する方法は、VMで使用できるクラスの実装が1つだけであることを確認することです。これには、ビルドスクリプトとの戦いが少し必要になる場合があります。
APKの内容は「dexdump」で表示できます。 (もう少し簡潔な「dexlist」もありますが、それがSDKの一部であるかどうかは覚えていません。)
@faddenが言ったように、同じコードが2つの異なるAPKにあります。これは、テストとテスト済みプロジェクトの両方が同じAndroid=ライブラリプロジェクトに依存している場合に発生します。ライブラリプロジェクトは他のライブラリプロジェクトに依存している可能性があるため、直接である必要はありません。
Antルールファイルの問題は修正されたようです。少なくともSDKツールr11では。混乱した人のために、コンパイルターゲットはmail_rules.xml
ではなくtest_rules.xml
にあります。
元のプロジェクトから新しい.classファイルを生成する代わりに、テストapkに.classファイルを含めようとしましたか?これは私の場合の問題を解決しました。
Android update test-project -m <project path> -p <test project path>
ant clean
ant debug
これらのコマンドを実行した後、antテストを実行できます。注:JUnit関連のエラーが発生する場合は、Junit jarファイルをテストプロジェクトのlibsフォルダーに追加してください。
Mavenによって実行されている単体テストで同じ問題に直面しました。 Androidライブラリがメインプロジェクトによって既にインポートされているライブラリへのリンクを削除することで、問題が修正されました。
テストするプロジェクトの範囲はコンパイルする必要があり、ライブラリの範囲を提供する必要があります。
詳しくは こちら をご覧ください