java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation getting while running test project?

24,854

Solution 1

You are getting this error because of third party library reference added two times. You have added the application path in the build path of test project. so the library reference automatically added to test project". Remove any library reference in the test project under properties->android.

FYI, click here for detail explanation.

Solution 2

It is because zxing jar files are being loaded twice, You must set the zxing library as "Provided" (if you are compiling your code using Maven) in compile time, so it does not add the library to your bytecode. that way you wouldn't get the error

Solution 3

Unfortunately, the best solution which i have seen, it's to use a script with these code lines and using Espresso v2.0:

adb shell setprop dalvik.vm.dexopt-flags v=n,o=v
adb shell stop installd
adb shell start installd

Execute it before you begin to test. It's only necessary to do it once time.

Solution 4

I changed test project setting in Intelij Idea. Go to Modules -> Dependencies, then set scope of the tested project to 'Provided'.

Solution 5

I got this error because I was working with Guava and Espresso also contains Guava.

If you use Gradle and Android Studio you can exclude packages from the dependency like this:

androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') {
   exclude group: 'com.google.guava'
}
Share:
24,854
ADIT
Author by

ADIT

Java & Android Developer.

Updated on December 03, 2020

Comments

  • ADIT
    ADIT over 3 years

    I have implemented project by using third party library(zxing) after implementation project is working fine then after I have written one test project to unit test my project.After running the test project ,the main project ,classes and it's methods are not giving any errors but if any zxing framework class is utilyzed within that method of the main project there getting the above error at run time not yet compile time.Please tell me how to resolve this issue?