kotlin Android Espresso测试错误:没有静态方法loadSingleServiceOrNull()

mxg2im7a  于 2023-03-09  发布在  Kotlin
关注(0)|答案(3)|浏览(139)

当我运行我的测试1周前一切都很好,但现在我得到这个错误:

java.lang.NoSuchMethodError: No static method loadSingleServiceOrNull(Ljava/lang/Class;)Ljava/lang/Object; in class Landroidx/test/internal/platform/ServiceLoaderWrapper; or its super classes (declaration of 'androidx.test.internal.platform.ServiceLoaderWrapper' appears in /data/app/com.domain.myapp-1/base.apk)
at androidx.test.espresso.base.UiControllerModule.provideUiController(UiControllerModule.java:2)
at androidx.test.espresso.base.UiControllerModule_ProvideUiControllerFactory.provideUiController(UiControllerModule_ProvideUiControllerFactory.java:1)
at androidx.test.espresso.base.UiControllerModule_ProvideUiControllerFactory.get(UiControllerModule_ProvideUiControllerFactory.java:1)
at androidx.test.espresso.base.UiControllerModule_ProvideUiControllerFactory.get(UiControllerModule_ProvideUiControllerFactory.java:2)
at androidx.test.espresso.core.internal.deps.dagger.internal.DoubleCheck.get(DoubleCheck.java:6)
at androidx.test.espresso.DaggerBaseLayerComponent$ViewInteractionComponentImpl.viewInteraction(DaggerBaseLayerComponent.java:1)
at androidx.test.espresso.Espresso.onView(Espresso.java:1)

此行抛出错误:

onView(withId(R.id.sign_in_button)).perform(click())

可能是什么原因?谢谢。

3mpgtkmj

3mpgtkmj1#

更新时出现问题

androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

恢复到版本3.3.0修复了一些问题。

ie3xauqp

ie3xauqp2#

您有多个ServiceLoaderWrapper,其中一些实际具有API方法,此文件由androidx.test:monitor带来,我通过强制应用Gradle文件中的软件包版本修复了它,如下所示。

android {
  ...
  configurations.all {
    resolutionStrategy {
        force 'androidx.test:monitor:1.4.0'
     }
  }
  ...
}
lskq00tm

lskq00tm3#

我升级到3.5.1并删除了espresso-contrib依赖项,解决了这个问题

相关问题