I am trying to migrate from Dagger2 to Hilt following the reference: https://developer.android.com/training/dependency-injection/hilt-jetpack#workmanager
But when I build my app, it fail with below error log:
/Users/.../myapp/build/tmp/kapt3/stubs/devDebug/.../MyWorker.java:13: error: incompatible types: NonExistentClass cannot be converted to Annotation
@error.NonExistentClass()
^
And here is the line 13:
line 11 @error.NonExistentClass()
line 12 public MyWorker(@org.jetbrains.annotations.NotNull()
line 13 @error.NonExistentClass()
line 14 android.content.Context appContext, @org.jetbrains.annotations.NotNull()
line 15 @error.NonExistentClass()
line 16 androidx.work.WorkerParameters params, @org.jetbrains.annotations.NotNull()
I don't know how can I fix it...
What I using versions are:
// kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.21"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.5.21"
// Hilt
implementation "com.google.dagger:hilt-android:2.35"
kapt "com.google.dagger:hilt-android-compiler:2.35"
implementation 'androidx.hilt:hilt-work:1.0.0'
kapt 'androidx.hilt:hilt-compiler:1.0.0'
// WorkManager
implementation "androidx.work:work-runtime-ktx:2.5.0"
implementation "androidx.work:work-rxjava2:2.5.0"
These versions are the latest and stable versions.
I tried to add the below Gradle setting but it's same error...
kapt {
correctErrorTypes true
}
Whooooooooo.....
I found the cause...
I'm sorry for all...
I am Korean, so I have been watching this guidance document for the Korean version: https://developer.android.com/training/dependency-injection/hilt-jetpack
But I found it is too old!
It guides to use @WorkerInject
in the Korean version, But it guides to use @AssistedInject
in the English version...
When I change it, the error disappeared...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.