【发布时间】:2017-05-14 16:25:31
【问题描述】:
该应用包含一个短暂显示的初始屏幕,并且该活动正在使用 IdlingResource 进行插桩测试,以便测试知道何时关闭初始屏幕。问题在于,在运行 API 19 的设备上进行测试期间,SplashActivity 会抛出看起来与依赖相关的异常:
import android.support.test.espresso.idling.CountingIdlingResource;
...
private CountingIdlingResource espressoTestIdlingResource =
new CountingIdlingResource("Splash_Delay"); // <-- Exception here line 22
...
app/build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.code.findbugs'
exclude module: 'espresso-idling-resource'
exclude group: "javax.inject"
})
compile 'com.android.support.test.espresso:espresso-idling-resource:2.2.2'
compile 'com.google.dagger:dagger:2.10'
annotationProcessor 'com.google.dagger:dagger-compiler:2.10'
compile 'com.google.dagger:dagger-android:2.10'
compile 'com.google.dagger:dagger-android-support:2.10'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.10'
compile "com.android.support:appcompat-v7:$supportLibraryVersion"
compile "com.android.support:design:$supportLibraryVersion"
compile "com.android.support.constraint:constraint-layout:1.0.2"
compile "com.jakewharton.timber:timber:4.5.1"
compile "com.squareup.phrase:phrase:1.1.0"
compile "com.squareup.retrofit2:retrofit:2.2.0"
compile "com.squareup.retrofit2:converter-gson:2.2.0"
compile "com.squareup.okhttp3:logging-interceptor:3.7.0"
compile 'net.danlew:android.joda:2.9.9'
testCompile 'junit:junit:4.12'
compile 'com.google.firebase:firebase-crash:10.2.4'
androidTestCompile 'junit:junit:4.12'
}
例外:
java.lang.IllegalAccessError
java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
at com.myapp.android.ui.splash.SplashActivity.<init>(SplashActivity.java:22)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.accessX800(ActivityThread.java:135)
at android.app.ActivityThreadXH.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInitXMethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
异常发生在 Firebase 测试实验室的 API 级别 19 Nexus 4 物理设备上。它不会出现在我们正在测试的任何其他平台上,包括本地 API 19 模拟 Nexus S。
我理解异常意味着存在模棱两可/重复(传递)依赖项,但我在 gradlew 依赖项中看不到任何依赖项,只有 Espresso Idling Resources v2.2.2。依赖项是“编译”而不是“androidTestCompile”,因为 Activity 中引用了 CountingIdlingResource。
如何确定原因并解决?
更新:Nexus 5 和 Nexus 7 上的 API 19 也会发生异常。以下是与空闲资源库相关的“./gradlew dependencies”输出部分:
_debugApk - ## Internal use, do not manually configure ##
+--- com.android.support.test.espresso:espresso-idling-resource:2.2.2
+--- com.google.dagger:dagger:2.10
...
_debugCompile - ## Internal use, do not manually configure ##
+--- com.android.support.test.espresso:espresso-idling-resource:2.2.2
+--- com.google.dagger:dagger:2.10
...
_releaseApk - ## Internal use, do not manually configure ##
+--- com.android.support.test.espresso:espresso-idling-resource:2.2.2
+--- com.google.dagger:dagger:2.10
...
_releaseCompile - ## Internal use, do not manually configure ##
+--- com.android.support.test.espresso:espresso-idling-resource:2.2.2
+--- com.google.dagger:dagger:2.10
...
compile - Classpath for compiling the main sources.
+--- com.android.support.test.espresso:espresso-idling-resource:2.2.2
+--- com.google.dagger:dagger:2.10
【问题讨论】:
-
这可能是个愚蠢的建议,但您是否在物理设备上运行测试之前禁用了动画?
-
测试是在 BuddyBuild CI 上运行的,他们使用 Firebase 测试实验室进行设备测试,所以我希望动画被关闭,这似乎很可能,因为我知道之前的许多测试都失败了CI 服务器,直到我们关闭它们。但我不确定动画是否是问题所在,因为该应用似乎正在寻找与空闲资源相关的意外类,而不是在测试验证失败的更常见意义上失败。
-
好的,我明白了。我想上次我看到这种类似的问题是因为 espresso 库是用旧版本的 Android 支持库编译的,而我在项目中使用了最后一个。同样,我只在 Android 4.4 设备上观察到了这一点。所以,最后只有这个解决方法对我有用 - stackoverflow.com/a/28862902/2241008。希望对你也有帮助。
-
该问题是依赖被引用两次的问题,但在我的情况下,我明确引用它只引用一次。其他依赖项都没有对 CountingIdlingResource 的传递依赖项。此类在支持库中定义,因此不包含在设备上的 API 19 中。这个错误对我来说毫无意义。
-
您使用的是哪个版本的支持库?你试过旧版本吗?
标签: android android-gradle-plugin android-espresso