Description
We have seen many reported crashes related to this particular WorkManager 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.
However, the OneSignal SDK uses the default WorkManagerInitializer and does not disable it. We are collecting information to investigate any solutions on our end as well as make a report of this to Google, as this seems to be related to an AndroidX library that OneSignal uses. For reference, these are reports of this and related exceptions to Google's Issue Tracker.
Current status
Google Issue Tracker
We reported this to Google's WorkManager issues here.
Summary
From reported stacktraces, the crash arises from OSNotificationRestoreWorkManager.beginEnqueueingWork(), OSFocusHandler.cancelOnLostFocusWorker() , and OSFocusHandler.startOnLostFocusWorker().
We know this can be related to multiprocess, but we have also seen many reports of this exception in applications that don't use multiprocess.
This is happening on applications that don't use WorkManager themselves and don't use Custom WorkManager Configuration and Initialization.
OneSignal maintainers have not been able to reproduce this crash, and users have not reported being able to reproduce this crash either. While there have been reports of some apps encountering this crash 100% of the time, those cases are related to other underlying issues.
This crash is also happening across multiple versions of androidx.work:work-runtime including on the latest stable release 2.7.1. It also appears to affect devices across types, brands, and Android versions.
We speculate it may have to do with the initialization of libraries and components during an app's startup process, and encountering edge cases where OneSignal tries to access the WorkManager singleton but it has not yet been initialized by the system. This crash happens when the OneSignal SDK calls WorkManager.getInstance(Context) and the WorkManager is null.
Also from Android docs, content providers are created on the application main thread at application launch time and Android initializes content providers in an undetermined order. If there are many providers to initialize, the one that contains the WorkManagerInitializer may not get created until later in the process, making the edge case more likely. In addition, if other <providers>s in the Manifest have initOrder set, those will initialize first.
Details Appreciated
To investigate further and gather insight into this crash's relationship to the app startup process, please tell us as much of the following information as possible.
-
Confirm that you are not using custom WorkManagerInitializer yourself.
-
Please look in the Merged Manifest for all the <provider> tags you have. Please provide the exact content of all of them. This information is informative as we speculate that having more ContentProviders may cause this crash to happen more often. Providing the full information helps us know which ones are involved. Here is an example:
<provider
android:name="com.google.firebase.provider.FirebaseInitProvider"
android:authorities="{myApplicationId}.firebaseinitprovider"
android:directBootAware="true"
android:exported="false"
android:initOrder="100" />
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="{myApplicationId}.androidx-startup"
android:exported="false" >
<meta-data
android:name="androidx.lifecycle.ProcessLifecycleInitializer"
android:value="androidx.startup" />
<meta-data
android:name="androidx.work.WorkManagerInitializer"
android:value="androidx.startup" />
</provider>
<provider
android:name="io.intercom.android.sdk.IntercomInitializeContentProvider"
android:authorities="{myApplicationId}.IntercomInitializeContentProvider"
android:exported="false" />
// ... and more
-
Look in the Merged Manifest or run ./gradlew app:dependencies to tell us the version of androidx.work:work-runtime your app is using.
-
Analytics of this crash: What devices and Android versions are experiencing the crash? Are there some devices or Android versions that are affected more?
-
Analytics of this crash: How many users and what percent of your users experienced this crash?
-
The stacktrace for this crash.
-
The version of the OneSignal-Android-SDK your app is using.
-
Are you able to reproduce this crash yourself?
-
Do you have information about when you started seeing this crash, what changes were made?
Possible Fix on the SDK User's End
Implement a custom WorkManagerInitializer for your app by following the On-Demand Initialization guide. Make sure to complete both steps for "Remove the default initializer" and "Implement Configuration.Provider".
This crash happens when the OneSignal SDK calls WorkManager.getInstance(Context) when the WorkManager singleton has not yet been initialized by the system, and the method will produce this exception. However, if an app implemented custom WorkManagerInitializer, this method will instead initialize the WorkManager singleton when it is null.
If you do this, please report back your results.
Description
We have seen many reported crashes related to this particular WorkManager IllegalStateException:
However, the OneSignal SDK uses the default
WorkManagerInitializerand does not disable it. We are collecting information to investigate any solutions on our end as well as make a report of this to Google, as this seems to be related to an AndroidX library that OneSignal uses. For reference, these are reports of this and related exceptions to Google's Issue Tracker.Current status
Google Issue Tracker
We reported this to Google's WorkManager issues here.
Summary
From reported stacktraces, the crash arises from
OSNotificationRestoreWorkManager.beginEnqueueingWork(),OSFocusHandler.cancelOnLostFocusWorker(), andOSFocusHandler.startOnLostFocusWorker().We know this can be related to multiprocess, but we have also seen many reports of this exception in applications that don't use multiprocess.
This is happening on applications that don't use WorkManager themselves and don't use Custom WorkManager Configuration and Initialization.
OneSignal maintainers have not been able to reproduce this crash, and users have not reported being able to reproduce this crash either. While there have been reports of some apps encountering this crash 100% of the time, those cases are related to other underlying issues.
This crash is also happening across multiple versions of
androidx.work:work-runtimeincluding on the latest stable release2.7.1. It also appears to affect devices across types, brands, and Android versions.We speculate it may have to do with the initialization of libraries and components during an app's startup process, and encountering edge cases where OneSignal tries to access the
WorkManagersingleton but it has not yet been initialized by the system. This crash happens when the OneSignal SDK callsWorkManager.getInstance(Context)and theWorkManagerisnull.Also from Android docs, content providers are created on the application main thread at application launch time and Android initializes content providers in an undetermined order. If there are many providers to initialize, the one that contains the
WorkManagerInitializermay not get created until later in the process, making the edge case more likely. In addition, if other<providers>s in the Manifest haveinitOrderset, those will initialize first.Details Appreciated
To investigate further and gather insight into this crash's relationship to the app startup process, please tell us as much of the following information as possible.
Confirm that you are not using custom WorkManagerInitializer yourself.
Please look in the Merged Manifest for all the
<provider>tags you have. Please provide the exact content of all of them. This information is informative as we speculate that having more ContentProviders may cause this crash to happen more often. Providing the full information helps us know which ones are involved. Here is an example:Look in the Merged Manifest or run
./gradlew app:dependenciesto tell us the version ofandroidx.work:work-runtimeyour app is using.Analytics of this crash: What devices and Android versions are experiencing the crash? Are there some devices or Android versions that are affected more?
Analytics of this crash: How many users and what percent of your users experienced this crash?
The stacktrace for this crash.
The version of the
OneSignal-Android-SDKyour app is using.Are you able to reproduce this crash yourself?
Do you have information about when you started seeing this crash, what changes were made?
Possible Fix on the SDK User's End
Implement a custom WorkManagerInitializer for your app by following the On-Demand Initialization guide. Make sure to complete both steps for "Remove the default initializer" and "Implement Configuration.Provider".
This crash happens when the OneSignal SDK calls
WorkManager.getInstance(Context)when theWorkManagersingleton has not yet been initialized by the system, and the method will produce this exception. However, if an app implemented customWorkManagerInitializer, this method will instead initialize theWorkManagersingleton when it isnull.If you do this, please report back your results.