Android Testing: IllegalAccessError

I get IllegalAccessError while testing Android hardware.
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 build path (on the Projects tab) and exports it from the Order and Export tab. The test class belongs to AnotherProject .

I followed this questionoverflow suggestion to set up the build path.

Build using Maven from the command line. AnotherProject is in the pom file for both TestProject and UnderTestProject as a dependency. Is this the reason for getting the error? How can i fix this? Include AnotherProject in pom for UnderTestProject only and include UnderTestProject in TestProject pom?

How is the eclipse build path related to maven pom?

I do not quite understand about this, and any help would be greatly appreciated.

Thanks!


I tried the following and still get the problem:

  • Removed AnotherProject from TestProject pom and added UnderTestProject to it.
  • Follow the tips of this thread. My UnderTestProject doesn't even build if I add <scope>provided</scope> to AnotherProject .

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

thanks!

+4
source share
3 answers

First, follow the Libraries section of the Android-a-maven wiki page here :

If your project setup contains libraries, then they must also be added as <scope> provided </scope> otherwise they will be added to the test, which will lead to duplication of the error "Class ref in a pre-tested class allowed for unexpected implementation".

......

Note. Error No. 142, only libraries with packaging </ packaging> will work at this stage.

Then right-click on your UnderTestProject project, select Build Path β†’ Configure Build Path, check Maven Dependencies on the Order and Export tab: enter image description here

This works for me, hope this helps.

+1
source

I had the same problem. To fix this for me, I had to add the library dependencies in the main pom.xml application to the pom.xml test application, but add the <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 MyAppTest pom.xml:

 <dependency> <groupId>com.nineoldandroids</groupId> <artifactId>library</artifactId> <version>2.4.0</version> <scope>provided</scope> </dependency> 
+1
source

You did not indicate whether this is a problem only for Eclipse, or the project cannot build with Maven too (using android-maven-plugin ). In my case, both failed. Reason: Transitive dependencies on UnderTestProject.apk also fall into TestProject.apk , causing a pre-verified class problem. The solution for me was to apply this in my TestProject 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 the manner discussed here gives a warning, but it does the job nicely (tested on Maven 3.1.1 ).

0
source

Source: https://habr.com/ru/post/1395475/


All Articles