OneSignal-Android-SDK icon indicating copy to clipboard operation
OneSignal-Android-SDK copied to clipboard

java.lang.IllegalStateException:WorkManager is not initialized properly

Open jinkaiYu opened this issue 2 years ago • 20 comments

image

jinkaiYu avatar Apr 07 '22 11:04 jinkaiYu

We're seeing the same issues here after upgrading from OneSignal 3 to OneSignal 4. Have spent a few hours debugging it, but cannot figure out where the issues lies. Any ideas?

2022-04-13 10:53:10.623 19262-19456/XXXXXXXXXXXXXXX E/AndroidRuntime: FATAL EXCEPTION: OS_REST_SUCCESS_CALLBACK
    Process: XXXXXXXXXXXXXXX:webactivity, PID: 19262
    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.
        at androidx.work.impl.WorkManagerImpl.getInstance(WorkManagerImpl.java:158)
        at androidx.work.WorkManager.getInstance(WorkManager.java:184)
        at com.onesignal.OSNotificationRestoreWorkManager.beginEnqueueingWork(OSNotificationRestoreWorkManager.java:48)
        at com.onesignal.OneSignal.handleActivityLifecycleHandler(OneSignal.java:968)
        at com.onesignal.OneSignal.init(OneSignal.java:845)
        at com.onesignal.OneSignal.setAppId(OneSignal.java:730)
        at com.onesignal.OneSignal.reassignDelayedInitParams(OneSignal.java:1174)
        at com.onesignal.OneSignal.onRemoteParamSet(OneSignal.java:882)
        at com.onesignal.OneSignal$7.complete(OneSignal.java:1115)
        at com.onesignal.OneSignalRemoteParams.processJson(OneSignalRemoteParams.java:206)
        at com.onesignal.OneSignalRemoteParams.access$100(OneSignalRemoteParams.java:12)
        at com.onesignal.OneSignalRemoteParams$1.onSuccess(OneSignalRemoteParams.java:151)
        at com.onesignal.OneSignalRestClient$5.run(OneSignalRestClient.java:292)
        at java.lang.Thread.run(Thread.java:920)

We call the init in the ApplicationClass. If we don't set the app ID or if we don't call the init function, it doesn't crash.

OneSignal.setLocationShared(false);
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);
OneSignal.setNotificationOpenedHandler(new NotificationOpenHandler(this));
OneSignal.initWithContext(this);
OneSignal.setAppId(appId);

mbardelmeijer avatar Apr 13 '22 08:04 mbardelmeijer

Hi @jinkaiYu and @mbardelmeijer,

This is a crash we are investigating. Please provide the following information to help us:

  1. Please provide the merged manifest information for the <provider> that has WorkManagerInitializer. For example, like this:
<provider
    android:authorities-"uninitialized.application.id.androidx-startup"
    android:exported="false"
    android:name="androidx.startup.InitializationProvider" >
        <meta-data
            android:name-"androidx.work.WorkManagerInitializer"
            android:value="androidx. startup" />
  1. Please provide your version of androidx.work:work-runtime, which can be found when looking at the merged manifest information. Screen Shot 2022-04-28 at 3 04 58 PM

  2. Are you able to reproduce this crash yourself?

  3. What devices and Android versions are experiencing the crash?

  4. What percent of your users experienced this crash? This gives us information into the rarity of when this occurs.

  5. Do you have information about when you started seeing this crash? For example, you started using OneSignal 2 months ago and have had this crash since the beginning, or, you started using OneSignal a year ago and only started seeing this crash in the last 3 months, etc...

This is a lot of questions and thank you for the information you can provide.

nan-li avatar Apr 28 '22 22:04 nan-li

@nan-li I've tried to aggregate the data, but we don't use a custom WorkManagerInitializer, so I'm already stuck on 1) haha.

I've tested OneSignal Android with a fresh Java project and it works there, but in our existing (upgraded) project it doesn't. The project contains an app and a shared library which contains the OneSignal logic.

The crash happens after the initWithContext method is called, and happens on every try.

Happy to chat about it in a closed chat to be able to share our set-up to help further debug this.

mbardelmeijer avatar May 03 '22 18:05 mbardelmeijer

Hi @mbardelmeijer,

Thank you for following up, and you are able to reproduce this crash yourself in the existing project?

For 1) and 2) OneSignal has androidx.work:work-runtime as a dependency, so the WorkManagerInitializer info in the merged manifest may not come from your own app if you don't use it, but from our SDK (or any other libraries you have that also use WorkManager). It would be good to know how it resolves in the merged manifest and the version of work-runtime your app ends up using.

I would very much appreciate your time to continue discussing. To do so, please reach out to [email protected], and reference this Github Issue.

nan-li avatar May 03 '22 21:05 nan-li

@nan-li thanks! I've checked, it resolves to work-runtime:2.7.1 manifest. I've sent the email to support with the full manifest details. :)

mbardelmeijer avatar May 04 '22 11:05 mbardelmeijer

@nan-li Sorry, I just saw the email. we used the version of work-runtime library is 2.5.0 and OneSignal SDK version is 4.7.1, I cant reproduce it by myself.

jinkaiYu avatar May 05 '22 01:05 jinkaiYu

I solved this bug by removing these two attributes from my AndroidManifest.xml file.

<application
    android:label="@string/android_app_name" 
    android:icon="@drawable/Icon"
    android:largeHeap="true" 
    android:hardwareAccelerated="false" 
    android:allowBackup="false" 
    android:fullBackupContent="false" 
    tools:node="replace" 
    tools:ignore="GoogleAppIndexingWarning" 
    android:networkSecurityConfig="@xml/network_security_config">

Remove the tools:node="replace" attribute.

<activity 
    android:name="com.facebook.FacebookActivity" 
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" 
    android:theme="@android:style/Theme.Translucent.NoTitleBar" 
    android:label="@string/facebook_app_name" />

Remove the android:theme="@android:style/Theme.Translucent.NoTitleBar" attribute.

pedropga avatar Sep 08 '22 15:09 pedropga

@pedropga Very interesting thank you for the workaround! Removing just one of the two did not fix the issue but removing both did?

emawby avatar Sep 08 '22 16:09 emawby

Yes, just removing both attributes that worked.

pedropga avatar Sep 08 '22 16:09 pedropga

Hi @pedropga,

Thanks for sharing. I have a follow-up question.

  1. Was this a crash you experienced only in production?
  2. Or were you able to reproduce it before adding your fix? If you reproduced it, was it happening all the time or rarely?

Thanks

nan-li avatar Sep 19 '22 22:09 nan-li

@nan-li

  1. It was happening in any environment, debugging, production, whatever.
  2. It was happening all the time, the app never started.

Without the OneSignal SDK, the application worked with those values in AndroidManifest, but it always crashed when I added the OneSignal SDK.

pedropga avatar Sep 19 '22 22:09 pedropga

Faced this crush either. Unable to make given workaround. Craches are in production enviroment from time to time, mostly on Android 7. Could you rate this issue?

sbrednikhin avatar Sep 29 '22 11:09 sbrednikhin

We have the same issue after upgrading to version 4.8.1.

Fatal 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.
androidx.work.impl.WorkManagerImpl.getInstance (WorkManagerImpl.java:158)

androidx.work.WorkManager.getInstance (WorkManager.java:184)
com.onesignal.OSNotificationRestoreWorkManager.beginEnqueueingWork (OSNotificationRestoreWorkManager.java:48)
com.onesignal.OneSignal.handleActivityLifecycleHandler (OneSignal.java:975)
com.onesignal.OneSignal.init (OneSignal.java:852)
com.onesignal.OneSignal.setAppId (OneSignal.java:735)
com.onesignal.OneSignal.reassignDelayedInitParams (OneSignal.java:1181)
com.onesignal.OneSignal.onRemoteParamSet (OneSignal.java:889)
com.onesignal.OneSignal$7.complete (OneSignal.java:1122)
com.onesignal.OneSignalRemoteParams.processJson (OneSignalRemoteParams.java:211)
com.onesignal.OneSignalRemoteParams.access$100 (OneSignalRemoteParams.java:12)
com.onesignal.OneSignalRemoteParams$1.onSuccess (OneSignalRemoteParams.java:156)
com.onesignal.OneSignalRestClient$5.run (OneSignalRestClient.java:279)
Caused by 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.
androidx.work.impl.WorkManagerImpl.getInstance (WorkManagerImpl.java:158)
androidx.work.WorkManager.getInstance (WorkManager.java:184)
com.onesignal.OSFocusHandler.startOnLostFocusWorker (OSFocusHandler.kt:85)
com.onesignal.ActivityLifecycleHandler.handleLostFocus (ActivityLifecycleHandler.java:183)
com.onesignal.ActivityLifecycleHandler.onActivityPaused (ActivityLifecycleHandler.java:102)
com.onesignal.ActivityLifecycleListener.onActivityPaused (ActivityLifecycleListener.java:97)
android.app.Application.dispatchActivityPaused (Application.java:249)
android.app.Activity.onPause (Activity.java:1677)
org.libsdl.app.SDLActivity.onPause (SDLActivity.java:332)
com.somecompany.packages.helpers.CustomActivity.onPause (CustomActivity.java:188)
android.app.Activity.performPause (Activity.java:7139)
android.app.Instrumentation.callActivityOnPause (Instrumentation.java:1330)
android.app.ActivityThread.performPauseActivityIfNeeded (ActivityThread.java:4165)
android.app.ActivityThread.performPauseActivity (ActivityThread.java:4142)
android.app.ActivityThread.performPauseActivity (ActivityThread.java:4116)
android.app.ActivityThread.handlePauseActivity (ActivityThread.java:4090)
android.app.ActivityThread.-wrap18 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1660)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6780)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1500)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1390)

We are unable to reproduce it. library work-runtime-2.7.0

84% Android 7 8% Android 11 42% Samsung devices (Galaxy Tab S2, Galaxy A10s and others)

Do you have any updates on this issue?

alekssunsss avatar Sep 30 '22 07:09 alekssunsss

it looks like this crash is very critical for us. We have a lot of users facing this issue mostly on Android 7. Do you have any updates?

alekssunsss avatar Oct 12 '22 12:10 alekssunsss

remove tools:node="replace" fix it

skinnynpale avatar Oct 25 '22 16:10 skinnynpale

Hi everyone, I apologize for the delay.

We didn't understand why this crash is happening as the error message " You have explicitly disabled WorkManagerInitializer in your manifest..." is misleading. After investigating, we believe we have enough insight into why this crash is occurring, which is a timing issue for initializing and accessing components at app startup.

A more thorough post on this issue is here: https://github.com/OneSignal/OneSignal-Android-SDK/issues/1672.

A workaround on the SDK user's end is to 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".

Another speculative fix is to add a high initOrder to the <provider> that contains WorkManagerInitializer within it, so that it runs earlier. You will have to manually add it to your own Android Manifest to override the <provider> in the merged manifest.

nan-li avatar Oct 25 '22 18:10 nan-li

@pedropga Thanks for your help! it's worked for me.

rehmanjameel avatar Dec 21 '22 08:12 rehmanjameel

@rehmanjameel Thanks for letting us know! Which changes did you have to make in your AndroidManifest.xml noted from https://github.com/OneSignal/OneSignal-Android-SDK/issues/1561#issuecomment-1240890456 above?

@rehmanjameel @pedropga Also if you can provide the detailed requested here that would be helpful for us to find the root case to this issue: https://github.com/OneSignal/OneSignal-Android-SDK/issues/1672

jkasten2 avatar Dec 21 '22 16:12 jkasten2

Have you seen the last message (Jan 3, 2023 08:31PM) in the Google thread? https://issuetracker.google.com/issues/258176803

alekssunsss avatar Jan 09 '23 10:01 alekssunsss

Anyone who is having this issue please update to OneSignal-Android-SDK 4.8.5 as this should address this issue.

Please report back if updating to this version fixes the issue for you or if you continue to see these same crashes.

jkasten2 avatar Apr 28 '23 05:04 jkasten2

Closing due to no response. Please let us know if upgrading to at least 4.8.5 has resulted in further crashes.

Much of our work in the last few quarters have been on a new major release where many improvements and enhancements are introduced. We will continue to investigate 4.x.x bugs, though we encourage you to update to our latest release as that will be the most-supported release going forward. Please see our migration guide for full details on upgrading.

Please let us know if you have any questions!

jennantilla avatar Mar 13 '24 22:03 jennantilla