java.lang.IllegalAccessError:预验证类中的类ref解析为运行测试项目时意外实现?

ADI*_*DIT 30 junit android unit-testing

我已经在实施项目工作正常后使用第三方库(zxing)实现了项目,然后我编写了一个测试项目来对我的项目进行单元测试.运行测试项目后,主项目,类和它的方法都没有给出任何项目.错误,但如果在主项目的方法中使用了任何zxing框架类,那么在运行时尚未编译时会出现上述错误.请告诉我如何解决此问题?

小智 33

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.


Hos*_*ost 11

这是因为zxing jar文件被加载了两次,你必须在编译时将zxing库设置为" 提供 "(如果你使用Maven编译你的代码),所以它不会将库添加到你的字节码中.这样你就不会得到错误


Jes*_*tro 8

不幸的是,我见过的最好的解决方案是使用带有这些代码行的脚本并使用Espresso v2.0:

adb shell setprop dalvik.vm.dexopt-flags v=n,o=v
adb shell stop installd
adb shell start installd
Run Code Online (Sandbox Code Playgroud)

在开始测试之前执行它.只需要一次就可以做到这一点.


Fed*_*dor 5

我改变了Intelij Idea中的测试项目设置.转到模块 - >依赖项,然后将测试项目的范围设置为"已提供".