我正在使用 Jake Wharton 的Double Espresso库在我的应用程序中设置仪器测试。测试在我的手机上运行良好,但在任何虚拟设备上都会崩溃(我尝试了模拟器和 Genymotion 设备)。
我得到的错误是IllegalAccessError
[previous](( Instrumentation run failed due to 'java.lang.IllegalAccessError'. Gradle + Espresso )。然而,令我困惑的是为什么它只发生在虚拟设备上。设置应该如果它能够在物理设备上运行就可以了。
堆栈跟踪包括所有地方的错误,但报告为致命的错误是:
java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
at com.myApp.onCreate(MyApp.java:32)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
无论如何,我尝试排除所有可能发生冲突的库,但我仍然无法让它工作。有没有人对问题可能是什么甚至如何排除故障有任何想法?
该问题似乎也与daggger
应用程序中使用的问题有关。MyApp:32 指向ObjectGraph
创建的行,以下两行在堆栈跟踪中。
W/dalvikvm﹕ Class resolved by unexpected DEX: Lcom/myApp/MyApp;(0xa4df7388):0x97542000 ref [Ldagger/ObjectGraph;] Ldagger/ObjectGraph;(0xa4df7388):0x97add000
W/dalvikvm﹕ (Lcom/myApp/MyApp; had used a different Ldagger/ObjectGraph; during pre-verification)
**更新:** 该问题可能与虚拟设备上的 Dalvik VM 有关。我的手机设置为 ART 并且之前曾报告过与 Dalvik 类似的问题。应该通过添加以下内容来修复它:
androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') {
exclude group: 'com.squareup.dagger'
}
根据图书馆页面,但这似乎没有帮助。