HiltWorkerFactory.createWorker is missing my HitlWorker class resulting in NoSuchMethodException
See original GitHub issueI am using 1.0.0-alpha03
with
androidx.hilt:hilt-work
com.google.dagger:hilt-android-compiler
com.google.dagger:hilt-compiler
I am experiencing the following issue:
java.lang.NoSuchMethodException: com.nicolasmilliard.socialcatsaws.imageupload.ImageUploadWorker.<init> [class android.content.Context, class androidx.work.WorkerParameters]
at java.lang.Class.getConstructor0(Class.java:2332)
at java.lang.Class.getDeclaredConstructor(Class.java:2170)
at androidx.work.WorkerFactory.createWorkerWithDefaultFallback(WorkerFactory.java:95)
at androidx.work.impl.WorkerWrapper.runWorker(WorkerWrapper.java:244)
at androidx.work.impl.WorkerWrapper.run(WorkerWrapper.java:136)
at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
While debugging I was able to identify than my app does use HiltWorkerFactory
but it’s createWorker
method is not able to retrieve my @HiltWorker
worker annotated class. It then delegate the creation to androidx.work.WorkerFactory.createWorkerWithDefaultFallback()
which in turn fails to create my HiltWorker
.
I can confirm that my build folder contains a ImageUploadWorker_Factory
generated class.
The test project I work on is open source.
The Worker code is available here
The Android Application code is available here
Let me know if you need anything else.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Hilt and WorkManager error : java.lang ...
Hilt and WorkManager error : java.lang.NoSuchMethodException:<init> [class android.content.Context, class androidx.work.WorkerParameters] ; @ ...
Read more >Android WorkManager Worker can not be injected using ...
NoSuchMethodException: <init> [class android.content. ... a sample app in comment#4 , looking at your build.gradle it seems you are missing a dependency:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@niqo01, you want to add
kapt("androidx.hilt:hilt-compiler:_")
in the library module (image-upload:android
) where the Worker source is, notice the difference in the group id, there are two compiler, the AndroidX one for the Jetpack extensions, including for Workersandroidx.hilt:hilt-compiler
and Hilt’scom.google.dagger:hilt-compiler
.Specifically in build.gradle.kts#L38 update the line to
kapt("androidx.hilt:hilt-compiler:_")
To be clear, whenever you use the
androidx.hilt
annotations, applyandroidx.hilt:hilt-compiler
. Meanwhile, wherever you usedagger.hilt
or justdagger
annotations, applycom.google.dagger.hilt:hilt-compiler
. If a combination of both are used, then apply both processors.thank you @danysantiago, that was it. I did not realized they were two different
hilt-compiler
…