RoverPlatform / rover-campaigns-android

Apache License 2.0
1 stars 0 forks source link

WorkManager Initialization Issue #68

Closed samwoodall closed 1 year ago

samwoodall commented 5 years ago

A small number of users are encountering crashes when we try to retrieve the workmanager instance in the CoreAssembler. This is due to the work manager not being properly initialized. The current method of initialization is a content provider being registered in the manifest by the work manager dependency. It appears that occasionally the onCreate of this is not being called before the application onCreate causing an IllegalStateException

A possible solution for this would be to update our workmanager dependency to the androidX version (requiring a migration of the entire sdk) which offers on demand initialization for the workmanager which would alleviate what appears to be a timing issue.

An example of the stacktrace for sdk version 3.2.1

Caused by 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 + 141(WorkManager.java:141)
       at io.rover.campaigns.core.data.sync.SyncCoordinator.ensureBackgroundSyncScheduled + 68(SyncCoordinator.java:68)
       at io.rover.campaigns.core.CoreAssembler.afterAssembly + 451(CoreAssembler.java:451)
       at io.rover.campaigns.core.container.InjectionContainer.initializeContainer + 21(InjectionContainer.java:21)
       at io.rover.campaigns.core.RoverCampaigns.initializeContainer(RoverCampaigns.java)
       at io.rover.campaigns.core.RoverCampaigns.<init> + 37(RoverCampaigns.java:37)
       at io.rover.campaigns.core.RoverCampaigns$Companion.initialize + 57(RoverCampaigns.java:57)