Reputation: 551
I wanted to use WorkManager with Hilt. I followed the docs and integrated the required dependencies like this into my gradle file:
// WorkManager library
implementation "androidx.work:work-runtime-ktx:$work_version"
// To use WorkManager with Hilt
implementation "androidx.hilt:hilt-work:workmanager_hilt_version"
// Annotation processor when using Kotlin
kapt "androidx.hilt:hilt-compiler:workmanager_hilt_version"
Note that the versions are work_version = "2.5.0"
and workmanager_hilt_version = "1.0.0-beta01"
.
Then I went to my Worker class and typed @HiltWorker
as described in the documentation BUT Android Studio could not find it:
@HiltWorker
class RefreshDataWorker @AssistedInject constructor(@Assisted appContext: Context, @Assisted params: WorkerParameters): CoroutineWorker(appContext, params) { ...// some doWork() stuff }
@HiltWorker
is in red letters and Android Studios can not find it. Why ? Does sth. changed in Hilt ? Is there sth. missing in the documentation ?
I hope someone can help.
Upvotes: 5
Views: 1480
Reputation: 1506
There are two choices:
1- Change "workmanager_hilt_version" from "1.0.0" to "1.0.0-alpha03". "@HiltWorker" is not available on "1.0.0"
https://developer.android.com/jetpack/androidx/releases/hilt
2- Add the "hilt-work" dependency:
implementation "androidx.hilt:hilt-work:1.0.0"
Upvotes: 4
Reputation: 11
Please change your workmanager hilt version from workmanager_hilt_version = "1.0.0-beta01" into workmanager_hilt_version = "1.0.0"
Upvotes: 0