NoClassDefFoundError when running Instrumentation test with ant
Asked Answered
M

6

7

(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.

Mandi answered 23/3, 2012 at 22:46 Comment(2)
The library folder name changed from lib to libs, but it sounds like maybe you already renamed it properly.Potheen
I changed that a few months ago when I had to start using command line tools and figured out the default ant build.xml uses different library folder than the Eclipse ADT plugin.Mandi
M
3

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 [email protected], 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\

Mandi answered 26/3, 2012 at 17:42 Comment(1)
thank you so much for this...! i thought i was losing my mind...!Tamis
C
38

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 :)

Coz answered 31/3, 2012 at 18:46 Comment(1)
thanks Levon it helped thank u so much..i was going crazy at thisLabrador
M
3

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 [email protected], 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\

Mandi answered 26/3, 2012 at 17:42 Comment(1)
thank you so much for this...! i thought i was losing my mind...!Tamis
B
2

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>
Buckeen answered 17/7, 2012 at 14:9 Comment(0)
E
1

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

Eth answered 24/3, 2012 at 4:19 Comment(1)
VerifyError is the error I get if I copy everything from testtarget/libs to testser/libs and vise versa. So I think you essentially have the exact same problem I got.Mandi
S
1

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.

Shadow answered 1/9, 2014 at 21:6 Comment(1)
Thanks, I can't believe this is so different from Flurry instructions! This is the one that is finally working for me!Thyrsus
P
0

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!!!

Paramour answered 14/8, 2014 at 0:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.