bambuser / BambuserPlayerSDK-Android

This project demonstrates how is the integration of Bambuser's Player SDK in an native Android application
Apache License 2.0
1 stars 1 forks source link

WorkManager is already initialized #11

Open SergioPoq opened 9 months ago

SergioPoq commented 9 months ago

When using BambuserPlayerSDK alongside other SDKs using WorkManager (in my case is Airship), the app crashes upon repeated app launches with the following error:

java.lang.RuntimeException: Unable to get provider androidx.startup.InitializationProvider: androidx.startup.StartupException: androidx.startup.StartupException: java.lang.IllegalStateException: WorkManager is already initialized.  Did you try to initialize it manually without disabling WorkManagerInitializer? See WorkManager#initialize(Context, Configuration) or the class level Javadoc for more information.
    at android.app.ActivityThread.installProvider(ActivityThread.java:7427)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6939)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6710)
    at android.app.ActivityThread.access$1500(ActivityThread.java:247)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2053)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7839)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: androidx.startup.StartupException: androidx.startup.StartupException: java.lang.IllegalStateException: WorkManager is already initialized.  Did you try to initialize it manually without disabling WorkManagerInitializer? See WorkManager#initialize(Context, Configuration) or the class level Javadoc for more information.
    at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:187)
    at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:238)
    at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:206)
    at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:45)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2404)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2374)
    at android.app.ActivityThread.installProvider(ActivityThread.java:7422)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6939) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6710) 
    at android.app.ActivityThread.access$1500(ActivityThread.java:247) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2053) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loopOnce(Looper.java:201) 
    at android.os.Looper.loop(Looper.java:288) 
    at android.app.ActivityThread.main(ActivityThread.java:7839) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 
Caused by: androidx.startup.StartupException: java.lang.IllegalStateException: WorkManager is already initialized.  Did you try to initialize it manually without disabling WorkManagerInitializer? See WorkManager#initialize(Context, Configuration) or the class level Javadoc for more information.
    at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:187)
    at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:173)
    at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:238) 
    at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:206) 
    at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:45) 
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2404) 
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2374) 
    at android.app.ActivityThread.installProvider(ActivityThread.java:7422) 
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6939) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6710) 
    at android.app.ActivityThread.access$1500(ActivityThread.java:247) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2053) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loopOnce(Looper.java:201) 
    at android.os.Looper.loop(Looper.java:288) 
    at android.app.ActivityThread.main(ActivityThread.java:7839) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 
Caused by: java.lang.IllegalStateException: WorkManager is already initialized.  Did you try to initialize it manually without disabling WorkManagerInitializer? See WorkManager#initialize(Context, Configuration) or the class level Javadoc for more information.
    at androidx.work.impl.WorkManagerImpl.initialize(WorkManagerImpl.java:200)
    at androidx.work.WorkManager.initialize(WorkManager.java:210)
    at androidx.work.WorkManagerInitializer.create(WorkManagerInitializer.java:39)
    at androidx.work.WorkManagerInitializer.create(WorkManagerInitializer.java:30)
    at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:180)
    at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:173) 
    at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:238) 
    at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:206) 
    at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:45) 
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2404) 
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2374) 
    at android.app.ActivityThread.installProvider(ActivityThread.java:7422) 
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6939) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6710) 
    at android.app.ActivityThread.access$1500(ActivityThread.java:247) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2053) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loopOnce(Looper.java:201) 
    at android.os.Looper.loop(Looper.java:288) 
    at android.app.ActivityThread.main(ActivityThread.java:7839) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 

The solution provided in the README is not feasible since I can't control all the WorkManager factories from other SDKs

JennyBambuser commented 9 months ago

Thank you for your feedback, we are looking into this issue

JennyBambuser commented 8 months ago

I found a tread discussing a similar issue with Airship, they suggested adding the following to your apps AndroidManifest.xml

<provider
        android:name="androidx.startup.InitializationProvider"
        tools:node="merge"
        android:authorities="${applicationId}.androidx-startup"
        android:exported="false">

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

        <meta-data
            android:name="com.urbanairship.AirshipInitializer"
            tools:node="remove" />

        <meta-data
            android:name="com.urbanairship.NoDependencyAirshipInitializer"
            android:value="androidx.startup" />
</provider>

I tested this in the BambuserPlayerSDK demo app and it removed the RuntimeException you mentioned above.

Could this solve your issue for now?

The discussion mentioned above also lead me to this issue registered with google. We will keep an eye on it to see if it might lead to an update of the WorkManager that could help us in solving this issue more permanently in the future.

SergioPoq commented 8 months ago

Yes, this solves the issue, thanks! It would be great if this issue gets resolved internally so we don't need to modify other SDKs

JennyBambuser commented 8 months ago

Great! Unfortunately the fix above can't be implemented on our side since the Bambuser Player SDK don't use Airship. Resolving the issue on our side would be optimal, and we will continue to look out for a solution but most likely we won't have a fix anytime soon.