Android Espresso test error: No static method loadSingleServiceOrNull()

Viewed 2760

When I ran my tests 1 week ago every was fine, but now I get this error:

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)

This line throws error:

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

What could be the cause? Thank you.

2 Answers

Issue occurred to me when I updated

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

to

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

Reverting to version 3.3.0 fixed things.

You have multiple ServiceLoaderWrapper, the one that actually has the API method is some of them, This file is brought by androidx.test:monitor, I fixed it by forcing the version of the package in the app gradle file as following.

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