Android WorkManager Worker can not be injected using Dagger Hilt `@WorkerInject`
Update (March 24, 2021):
Since androidx.work-*
version 2.6.0-alpha01
, WorkManager
uses androidx.startup
to initialize WorkManager.
For the new required changes to AndroidManifest.xml
, check this answer.
Original Answer:
As per the WorkManager Configuration and Initialization documentation, to use the Configuration.Provider
interface on your Application
, you must remove the default initializer:
<!-- In your AndroidManifest.xml -->
<provider
android:name="androidx.work.impl.WorkManagerInitializer"
android:authorities="${applicationId}.workmanager-init"
tools:node="remove" />
Otherwise, the default initializer will still run, wiping out your custom intialization and its HiltWorkerFactory
.