gpt4 book ai didi

android - CountingIdlingResource 的 IllegalAccessError

转载 作者:太空狗 更新时间:2023-10-29 16:28:48 26 4
gpt4 key购买 nike

该应用程序包含一个短暂显示的初始屏幕,该 Activity 正在使用 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'
}

异常(exception):

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

最佳答案

据我了解Google Samples依赖:

com.android.support.test.espresso:espresso-idling-resource:2.2.2

仅在您实现自定义 IdlingResource 时才需要。即使在 IdlingResourceSample README 中也有一句话:

Consider using the CountingIdlingResource class from the espresso-contrib package

据我了解您的代码,您正在尝试使用 espresso-contrib 包中的 CountingIdlingResource,因此请尝试按照其他 Google sample 中编写的方式组织您的测试依赖项.

关于android - CountingIdlingResource 的 IllegalAccessError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43966265/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com