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

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'
}