4

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!

Community
  • 1
  • 1
Chaitanya
  • 2,039
  • 4
  • 25
  • 32

3 Answers3

1

I had the same problem. To fix it for me, I had to add the library dependencies in the main app's pom.xml to the test app's pom.xml, but add <scope>provided</scope> to them.

So if I have the following dependency in MyApp pom.xml:

<dependency>
    <groupId>com.nineoldandroids</groupId>
    <artifactId>library</artifactId>
    <version>2.4.0</version>
</dependency>

I had to add this to the MyAppTest pom.xml:

<dependency>
    <groupId>com.nineoldandroids</groupId>
    <artifactId>library</artifactId>
    <version>2.4.0</version>
    <scope>provided</scope>
</dependency>
Jon Adams
  • 24,464
  • 18
  • 82
  • 120
1

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.

Community
  • 1
  • 1
yorkw
  • 40,926
  • 10
  • 117
  • 130
  • Thanks for the answer! I have moved to Robolectric for now, and have got tests running. However, I have to get the instrumentation tests going, and I will verify this once I reach instrumentation again. I am accepting your answer till then. – Chaitanya Feb 16 '12 at 00:52
0

You did not specify whether this is an Eclipse-only problem, or the project fails to build with Maven too (using the android-maven-plugin). In my case, both would fail. The reason: transitive dependencies from the UnderTestProject.apk would also find their way into TestProject.apk causing the pre-verified class problem. The solution for me was to apply this in my TestProject's pom:

<dependency>
    <groupId>com.example</groupId>
    <artifactId>UnderTestProject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <type>apk</type>
    <exclusions>
        <exclusion>
            <groupId>*</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Using wildcards in this manner, as discussed here, will produce a warning, but gets the job done beautifully (tested on Maven 3.1.1).

Community
  • 1
  • 1
dev
  • 1,648
  • 16
  • 25