dagger: IllegalStateException: Unsupported nesting ANONYMOUS on hilt 2.47
Upgrade Hilt from 2.46.1 to 2.47 and meet this error, seems this has been fixed few versions ago. https://github.com/google/dagger/issues/3760 https://issuetracker.google.com/issues/232742201
I’ve upgraded Android compile sdk to 34 recently, not sure if these have connections.
Execution failed for task ':app:hiltJavaCompileDebug'.
> java.lang.IllegalStateException: Unsupported nesting ANONYMOUS
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 9
- Comments: 15 (2 by maintainers)
@onXAdamBrown Just fyi, we have a 2.48 release planned for next week, so we’re going to push this into that release.
(Note: Dagger doesn’t maintain multiple release branches so it would be difficult for us to cut a 2.47.1 release with only this change without including the other larger (potentially breaking) changes.)
Thanks for the sample code, we have an idea on what is going on.
To workaround the issue for now, please specify the property type as to avoid Kotlin’s type resolution using an anonymous class, i.e.:
Fixed in https://github.com/androidx/androidx/commit/da6bd1a2f983372fd3ce34753d0b93bac7ec0361 which is the library Dagger uses for processing.
Yes, that’s correct.
Yes, I’ll try to get a release out early next week.
Thanks to the recent snapshot, I was able to identify the exact place in my code that causes an error. However, I don’t fully understand why Dagger complains about it. Note: I use only Dagger without Hilt.
There is a simplified snippet
anotherFieldcauses the problem. If I make it public, then compilation passes. But this field is not injected by Dagger. Am I missing something?At first I was thinking that it is somehow related to
injectedFieldusage insideanotherField. When I remove this usage, compilation still fails with the same error.Here is the full error
Hi @theobch, sorry we were waiting on a few dependencies to be updated.
The fix should be in the
HEAD-SNAPSHOTartifacts once this run finished: https://github.com/google/dagger/actions/runs/5665122541I have the same problem. When running debug for https://github.com/google/dagger/blob/master/java/dagger/internal/codegen/validation/InjectValidator.java#L380, the last Element was a regular Fragment with nothing special so im kinda stuck
No, it has not been pushed yet. I’ll update this thread once it’s out.
If you have access to https://github.com/google/dagger/blob/master/java/dagger/internal/codegen/validation/InjectValidator.java#L380 source then you should be able to get pretty close to where the issue is happening in your code by inspecting the elements there.