2014-06-25 37 views
1

我有一個使用Espresso的Android測試項目,我試圖用Ant構建。我可以很好地構建測試應用程序。將它安裝到設備和所有東西上。問題是,每當我試圖運行與Ant(build.xml)等價於Eclipse的構建路徑 - >導出?

亞行外殼上午儀器測試-w com.test.package/com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner

我得到這個在我的命令提示符:

INSTRUMENTATION_RESULT: shortMsg=java.lang.ClassNotFoundException 
INSTRUMENTATION_RESULT: longMsg=java.lang.ClassNotFoundException: Didn't find class "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner" on path: /system/framework/com.google.android.maps.jar:/system/framework/android.test.runner.jar:/data/app/test.apk:/data/app/myApp.apk 
INSTRUMENTATION_CODE: 0 

這在logcat中:

E/AndroidRuntime(27558):java.lang.RuntimeException:無法 實例化工具 ComponentInfo {com.avai.app.test.automate/com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner}: java.lang.ClassNotFoundException:找不到類 「com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner」 on path: /system/framework/com.google.android.maps.jar:/系統/框架/ android.test.runner.jar:/data/app/test.apk:/data/app/myApp.apk

我可以在Eclipse中運行測試,如果我請選中我濃縮咖啡罐在Configure Build Path->Order and Export下。我注意到,在未選中此框的情況下,我會得到與上述完全相同的錯誤消息。

我需要知道的是如何在Ant中模擬Eclipse的行爲?

這裏是我的build.xml文件(從Export->Ant build files在Eclipse中大多產生一個片段:

<path id="Android 4.4.2.libraryclasspath"> ... (lots of jars) ... </path> <path id="AutomationTests.classpath"> ... (more jars) ... </path> <path id="AutomationTests.classpath"> <pathelement location="bin/classes"/> <path refid="Android 4.4.2.libraryclasspath"/> <path refid="Android Private Libraries.libraryclasspath"/> <path refid="Android Dependencies.libraryclasspath"/> <pathelement location="../../android-test-kit/bin/espresso-standalone/espresso-1.1-bundled.jar"/> </path> <javac encoding="${java.encoding}" source="${java.source}" target="${java.target}" debug="true" extdirs="" includeantruntime="false" destdir="${out.classes.absolute.dir}" bootclasspathref="project.target.class.path" classpathref="project.javac.classpath"> ...(stuff) ... </javac>

回答

1

你看到的是不作爲第三方jar導致錯誤打包在APK中 android ant build的默認行爲是隻有在應用程序項目/ libs文件夾中找到的jar被打包到apk中 將espresso-1.1-bundled.jar複製到應用程序的/ libs文件夾項目,你會沒事的。

另一件需要考慮的事情 - 您將更好地使用Android工具生成build.xml,如下所述:http://developer.android.com/tools/projects/projects-cmdline.html#UpdatingAProject