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?
9 Answers
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.
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

- 1,692
- 18
- 32
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.

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

- 43,261
- 10
- 79
- 89
-
People of the future: you now need to use `compileOnly`, as `provided` is deprecated. – Sakiboy Nov 17 '20 at 20:20
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'
}

- 187,060
- 113
- 301
- 369
Uncheck the jars (in my case maps and google play services jar) from "Order and Export" tab under Project's Java build path in Eclipse.But let them be added in "Libraries" tab. Click OK, Clean projects and build now. It works.

- 89
- 2
- 7
If you do not specifically need a device with low API version (<=19), you can leave transitive dependencies and create an emulator with higher API version.
This happens only on devices which API is lower than Lollipop (API 21). Running tests on emulators higher/equal to API 21 runs normally, without issues.

- 60,783
- 13
- 169
- 249
I have this error on api level lower than 21. Just the build->rebuild project helped me.

- 2,565
- 25
- 31