NoClassDefFoundError when running Instrumentation test with ant

南楼画角 提交于 2019-11-28 08:01:43

问题


(This is an Android SDK tools v17 problem. Expect a fix in v18)

I have a test target project A, and a tester project B.

Project A has FlurryAgent.jar in its libs folder.

Project B has robotium-solo-3.1.jar in its libs folder

When I compile and run them,

cd A
android update project -p .
cd ..
cd B
android update test-project -p . -m ../A
ant all clean debug
ant uninstall
ant installt
ant test

ant test fails to execute tests:

test:
     [echo] Running tests ...
     [exec]
     [exec] com.example.r17.test.TestOne:
     [exec] INSTRUMENTATION_RESULT: shortMsg=java.lang.NoClassDefFoundError
     [exec] INSTRUMENTATION_RESULT: longMsg=java.lang.NoClassDefFoundError: com.flurry.android.FlurryAgent
     [exec] INSTRUMENTATION_CODE: 0

I've read some posts/questions that solve this problem in Eclipse. But I don't think I can run Eclipse on headless Jenkins slave.


回答1:


Since this post was the first in search engine results when I entered "java.lang.NoClassDefFoundError: com.flurry.android.FlurryAgent" and my issue was not related to Ant at all, I thought I'd add some info for people who might be scratching their heads after re-installing the ADT.

Basically, in Eclipse when you add an external library in the Java Build Path dialog, don't forget to also switch to the Order and Export tab and tick that library's name in the list. This is needed so that the library is found at run-time, not only at compile time :)




回答2:


http://code.google.com/p/android/issues/detail?id=27608

I submitted the issue to Google and they uploaded a temporary fix. The fix will also be included in v18 release.

"project member x...@android.com, Today (34 minutes ago) get the anttasks.jar from the bottom of http://tools.android.com/download to replace the one in your sdk."

The file to replace is at \Android\android-sdk\tools\lib\




回答3:


It took me a very long time to figure this same problem out when using android-junit-report, but with the help of "adb logcat" I discovered that it wasn't actually missing the instrumentation class that I included, but it was missing its inherited superclass. So I needed to put this back into AndroidManifest.xml:

<application>
    <uses-library android:name="android.test.runner" />
</application>



回答4:


I dont have the rep to comment Qi but I think this may be related to my question here:

VerifyError in android test-project build tools v17

Xav has been instrumental in getting this back up and running and looks like hes got a fix




回答5:


I have the same case and it doesn't work even if I followed Levon's post. Then I realized I need to copy the FlurryAnalytics.jar into the libs folder in my work space to make it work. Hope this helps.




回答6:


I have just fix this problem "08-14 08:33:43.398: E/AndroidRuntime(6748): java.lang.NoClassDefFoundError: com.flurry.android.FlurryAgent"

I flow the official web when I want to add the flurry to my android app,it tell me add an external library in the Java Build Path dialog, And then I don't forget to also switch to the Order and Export tab and tick that library's name in the list. This is needed so that the library is found at run-time, not only at compile time,But however it do not works until I just remove the jar from build path,and then copy it to the lib. Done!!!



来源:https://stackoverflow.com/questions/9847443/noclassdeffounderror-when-running-instrumentation-test-with-ant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!