Unable to get provider androidx.startup.InitializationProvider during the Compose tests

322 views Asked by At

Trying to run a simple Compose UI test. The SignUp screen contains a webview with the contentDescription that I'm checking in my test.

class SignUpTest {

@get:Rule
val signUpTestRule = createComposeRule()

@Test
fun verify_signUpWebView_isDisplayed() {
    signUpTestRule.setContent {
        TestTheme {
            SignUpScreen(
                signUpUiState = SignUpUiState(),
                signUpWebViewMessageListener = {

                }
            )
        }
    }

    with(signUpTestRule) {
        onNodeWithContentDescription("Sign up page").assertIsDisplayed()
    }
}

}

I have 2 issues here:

  1. The tests which run from Launcher Activity take ±40 secs to complete.

  2. Test finish successfully but in the finished - throws an exception:

    Logcat of last crash: 
    

Process: com.test.app, PID: 15790

java.lang.RuntimeException: Unable to get provider androidx.startup.InitializationProvider: java.lang.ClassNotFoundException: Didn't find class "androidx.startup.InitializationProvider" on path: DexPathList[[zip file "/data/app/~~ULkUjY-6LlUkmHkSUOjLCg==/com.test.app-9T9LoZkXgy-RnWTqEAtj_A==/base.apk"],nativeLibraryDirectories=[/data/app/~~ULkUjY-6LlUkmHkSUOjLCg==/com.test.app-9T9LoZkXgy-RnWTqEAtj_A==/lib/arm64, /system/lib64, /system_ext/lib64]]

    at android.app.ActivityThread.installProvider(ActivityThread.java:8463)


    at android.app.ActivityThread.installContentProviders(ActivityThread.java:7963)


    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7649)


    at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)


    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2478)


    at android.os.Handler.dispatchMessage(Handler.java:106)


    at android.os.Looper.loopOnce(Looper.java:230)


    at android.os.Looper.loop(Looper.java:319)


    at android.app.ActivityThread.main(ActivityThread.java:8893)


    at java.lang.reflect.Method.invoke(Native Method)


    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)


    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)


Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.startup.InitializationProvider" on path: DexPathList[[zip file "/data/app/~~ULkUjY-6LlUkmHkSUOjLCg==/com.test.app-9T9LoZkXgy-RnWTqEAtj_A==/base.apk"],nativeLibraryDirectories=[/data/app/~~ULkUjY-6LlUkmHkSUOjLCg==/com.test.app-9T9LoZkXgy-RnWTqEAtj_A==/lib/arm64, /system/lib64, /system_ext/lib64]]


    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)


    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)


    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)


    at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:147)


    at android.app.ActivityThread.installProvider(ActivityThread.java:8447)


    ... 11 more





BUILD SUCCESSFUL in 1m 41s

I added in my proguard-rules file these rules but the it didn't help:

# Keep the InitializationProvider class to prevent it from being stripped out.
-keep class androidx.startup.InitializationProvider { *; }
# Keep the names of classes that extend Initializer to ensure they are not obfuscated,
# which is necessary because these classes are looked up by name during app startup.
-keepnames class * extends androidx.startup.Initializer

# Keep the public no-argument constructors of Initializer implementations.
-keepclassmembers class * extends androidx.startup.Initializer {
    public <init>();
}

Also I tried to import the "androidx-startup-startup-runtime" dependency but without any success as well.

Does anyone knows why it happen ?

0

There are 0 answers