Android Robotium NoClassDefFoundError
Asked Answered
H

6

13

I was just trying to use Robotium in an Android JUnit Test, but the Testing always fails with an error:

java.lang.NoClassDefFoundError: com.jayway.android.robotium.solo.Solo

thrown at solo = new Solo(getInstrumentation(), getActivity()); in the setUp() method:

protected void setUp() throws Exception {
    super.setUp();
    solo = new Solo(getInstrumentation(), getActivity());
}

I read somewhere that this could be related to the Android SDK revision 17, but I cannot confirm this, as I first tried Robotium already with SDK 17.

The Robotium jar is properly added to the project build path.

Has anyone encountered similar problems?

Regards K.

Heelpost answered 26/3, 2012 at 15:30 Comment(0)
G
30

I had the same problem today. I solved by importing the jar into the libs directory of the test project and then adding it to the Build Path Libraries:

TestProject Properties -> Java Build Path -> Libreries -> Add JARs... -> TestProject/libs/robotium-solo-3.1.jar

Gantry answered 27/3, 2012 at 15:0 Comment(2)
the libs directory did the trick, thank you! but you shouldn't add them to the buil path then, because everything in libs is automatically added to the build path. (tools.android.com/recent/…).Heelpost
Hi Kim, i did not see any lib for my test project... where do i need to change this?Matutinal
V
25

You will need to export the Robotium jar by going to Properties-> Java Build Path -> Order and Export. Then check the Robotium jar file.

Vizcacha answered 29/3, 2012 at 22:41 Comment(0)
A
8

I did this configuration to solve the problem

enter image description here

Note : I put robotium first one.

Andras answered 7/2, 2014 at 15:0 Comment(0)
L
3

Had the same issue on SDK 17. Adding the robotium jar to lib and exporting helped. Also had to change the deprecated super call in the constructor from super(String,Class) to super(Class) to make it work.

Lodi answered 5/4, 2012 at 15:12 Comment(1)
I also had all three of these problems when trying to test a Jelly Bean application. Make sure you don't use the deprecated constructor.Earthenware
S
2

What I did to fix the bug was :

  • Remove the libraries from the standard Java build path :
  • Right click on the project name > Properties > Java Build Path > tab Libraries > remove everything except the “Android X.X” (2.3.3 in my case) and the “Android Dependencies”
  • Rename the libraries folder from “lib” to “libs”
  • By doing that, all the libraries in the folder “libs” are found by the Android plugin and are added to the “Android Dependencies” item of the project
  • Clean the project (not exactly needed)

You are good to go !

Sideswipe answered 6/8, 2012 at 18:8 Comment(0)
V
1

If the problem still persist just restart your eclipse. I was having same problem even after importing robotium.jar but after restarting eclipse it worked fine.

Virtuoso answered 18/5, 2014 at 12:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.