Char
Char

Reputation: 61

Android - UI Automation using Robotium using Eclipse

I am trying to run my UI tests for an Android project using Robotium, but whenever I try to run it, either from command line or Eclipse, it gives me this error:

INSTRUMENTATION_RESULT: longMsg=java.lang.IllegalAccessError: 
    Class ref in pre-verified class resolved to unexpected implementation

In logcat it also gives me an error that says:

java.lang.NoClassDefFoundError: com.bridgepointeducation.talon.TalonModule

even though I don't have a com.bridgepointeducation.talon.TalonModule.

Does anyone know how to fix this problem? Thanks!

Upvotes: 2

Views: 2521

Answers (3)

Indraneel
Indraneel

Reputation: 316

I faced a similar issues during instrumentation where i got the error Class ref in pre-verified class resolved to unexpected implementation

After log of struggle , i could solve the problem . The problem occurred due to android-support-v4.jar. This jar is by default created in lib folder of android project. The jars added to lib folder are used during compilation time as well as runtime for the instrumentation project. When I was running the instrumentation, the target application started using android-support-v4.jar bundled in the instrumentation project instead of its own android-support-v4.jar. This causes pre-verified class exception during runtime (as version will differ).

To solve this issue i moved out android-support-v4.jar out of lib folder and put it in a different folder (say libforcompile) and add it as external Jar (Project properties -> Java BUild Path --> Libraries --> click on Add External Jars).

THus my instrumentation project compiled fine and when it ran it used the android-support-v4.jar of the target app itself

No more error..

I hope it helps

Regards Indraneel

Upvotes: 1

Brian Yarger
Brian Yarger

Reputation: 1975

I've seen this problem when there are two copies of the same class/jar provided. For instance if you depend on a third party library in both your android project and the test project, for some reason it gets included twice.

It depends how you build/run your tests to determine how to fix this. From eclipse you can export the offending library in the android project, and it'll get put on the classpath of the test project. In maven, you can mark it as provided scope. In ant, I believe you'd just not include it locally in the test project (in libs or otherwise) and it'd get pulled from the android project classpath.

Upvotes: 7

JeffG
JeffG

Reputation: 3322

It sounds like the implementation classes that it is trying to run the tests against are not what it expects. When you run the tests, you have to specify the test package and the package to run the tests against.

Are you sure that the package it is running the tests against is the same as the package being included in the classpath? Maybe the tests are running against an outdated version?

Also, if your project includes any other libraries (.jars), you must ensure that they are included in the classpath of the tests too.

EDIT: looking around I found a similar problem and solution here: Can't build and run an android test project created using "ant create test-project" when tested project has jars in libs directory

You must alter your build.xml file to override some default android targets in order to include 3rd party libraries (.jars)

Upvotes: 0

Related Questions