Skip to content

During tests app crashes when trying to initialize WorkManager / WorkManager initializer is not invoked from androidx.startup.InitializationProvider #1026

@Roman-Markov

Description

@Roman-Markov

Appium: 2.10.3
Espresso driver: 3.3.0

When I added dependency to app under test

implementation 'androidx.work:work-runtime:2.9.0'

and later in code invoked

WorkManager.getInstance(context);

the app started to crash during appium tests with espresso driver.

Exception:
java.lang.IllegalStateException: WorkManager is not initialized properly. You have explicitly disabled WorkManagerInitializer in your manifest, have not manually called WorkManager#initialize at this point, and your Application does not implement Configuration.Provider.

Merged manifest file of the app under test has it declared to be initialized via androidx.startup.InitializationProvider

        <provider
            android:name="androidx.startup.InitializationProvider"
            android:exported="false"
            android:authorities="com.example.android.testing.espresso.BasicSample.androidx-startup">

            <meta-data
                android:name="androidx.work.WorkManagerInitializer"
                android:value="androidx.startup" />
        </provider>

My custom provider was initialized and worked fine. Also I copied code from androidx.startup.InitializationProvider to my second custom provider. It could initialize WorkManger on app launch before WorkManager.getInstance(context); was invoked.

Here is repos to reproduce the crash:

A bit modified android espresso sample app: https://github.com/Roman-Markov/appium-espresso-reproducible-crash
Simple appium test code: https://github.com/Roman-Markov/simple-appium-test-to-reproduce-crash

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions