2

我正在使用 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'
}

根据图书馆页面,但这似乎没有帮助。

4

1 回答 1

4

这个问题实际上是由espresso-support图书馆引起的。com.squareup.dagger当我只将排除项添加到另一个库时,我也需要在那里添加排除项。

androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') {
    exclude group: 'com.squareup.dagger'
}
androidTestCompile ('com.jakewharton.espresso:espresso-support-v4:1.1-r3') {
    exclude group: 'com.squareup.dagger'  // this goes here too
    exclude group: 'com.android.support', module: 'support-v4'
}
于 2014-05-21T03:19:00.280 回答