Search code examples
androidmaveninstrumentationbuildpath

android instrumentation testing : IllegalAccessError


I am getting the IllegalAccessError while running Android instrumentation tests.
This is Logcat output:

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

This is my setup:
TestProject tests UnderTestProject, which includes AnotherProject in the buildpath (in 'Projects' tab), and exports it from 'Order and Export' tab. The class under test belongs to AnotherProject.

I have followed the suggestion in this stackoverflow question here for configuring build path.

The builds are being done using Maven, from command line. AnotherProject is in the pom file for both TestProject and UnderTestProject, as dependency. Is this the reason for still getting the error? How can I fix this? Include AnotherProject in pom only for UnderTestProject and include UnderTestProject in the TestProject's pom?

How does eclipse's build path tie up with maven's pom?

I am not clear about this, and any help would be greatly appreciated.

Thanks!


I tried the following, and still getting the problem:

  1. Removed AnotherProject from TestProject's pom, and added UnderTestProject to it.
  2. Followed the advice on this thread. My UnderTestProject doesn't even build if I add <scope>provided</scope> for AnotherProject.

I am stuck at this point, please let me know if you have a way out.

thanks!


Solution

  • First, follow the Libraries section on android-maven-plugin wiki page here:

    If your project set-up contains libraries then those too need to be added as <scope>provided</scope> otherwise they will be added to the test which will result in a duplication the error «Class ref in pre-verified class resolved to unexpected implementation».

    ... ...

    Note Bug # 142, only Libraries with <packaging>jar</packaging> will work at this point.

    Then right-click on your UnderTestProject, click Build Path -> Configure Build Path, tick Maven Dependencies in the Order and Export tab:enter image description here

    This works for me, hope it helps.