该应用程序包含一个简短显示的启动画面,该活动正在使用一个检测测试,使用IdlingResource进行测试,以便测试知道启动画面何时关闭。问题是SplashActivity在运行API 19的设备上测试时会抛出与依赖项相关的异常:
import android.support.test.espresso.idling.CountingIdlingResource;
...
private CountingIdlingResource espressoTestIdlingResource =
new CountingIdlingResource("Splash_Delay"); // <-- Exception here line 22
...
应用程序/的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”,因为活动中引用了CountingIdlingResource。
如何确定原因并解决?
更新:Nexus 5和Nexus 7上的API 19也会出现异常。以下是与空闲资源库相关的“./gradlew依赖项”输出的部分:
_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
答案 0 :(得分:5)
据我了解Google Samples依赖:
com.android.support.test.espresso:espresso-idling-resource:2.2.2
只有在实施自定义IdlingResource
时才需要。即使在IdlingResourceSample
自述文件中也有一句话:
考虑使用espresso-contrib包中的CountingIdlingResource类
据我了解您的代码,您尝试使用espresso-contrib软件包中的CountingIdlingResource
,因此请尝试按照其他Google sample编写的方式组织测试依赖项。