I got an app that uses WorkManager
for several background tasks. Lately I see a lot of crashes in my production logs due to WM not being initialized even though I did not disable WorkManagerInitializer
in the manifest.
java.lang.IllegalStateException: WorkManager is not initialized properly. The most likely cause is that you disabled WorkManagerInitializer in your manifest but forgot to call WorkManager#initialize in your Application#onCreate or a ContentProvider.
at androidx.work.WorkManager.getInstance(WorkManager:161)
...
The WM documentation says
By default, WorkManager auto-initializes itself using a built-in ContentProvider. ContentProviders are created and run before the Application object, so this allows the WorkManager singleton to be setup before your code can run in most cases.
The interesting part there is in most cases. I wonder in what circumstances it is not initialized properly before the app starts.
My initial guess was that a bug in my code might have created too many WM tasks that take too long to initialize, but I was not able to recreate the crash in that way.
Anyone has seen this behavior before and has an idea what could go on here? Why is WorkManager
not initialized before app start?