-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hilt: compilation error for inherited Fragments #1910
Comments
I think it's safe to remove the Edit: What you're doing is you're putting a class inheritance of two entry points and Dagger gets confused, either move out all the injection in the base fragment and be okay with it or do as the guy below has written a beautiful explanation. |
We should be able to fix this internally. I'll work on getting this fix out shortly, but in the meantime there's the following workarounds. WorkaroundIn the meantime, you should be able to work around this using the long-form notation for
Edit: @Crazylegend's suggestion of removing Details:The issue is that when using the short-form notation for "Hilt_EditNoteFragment > CreateNoteFragment > Hilt_CreateNoteFragment > Fragment" But before the bytecode injection it's actually: "Hilt_EditNoteFragment > CreateNoteFragment > Fragment" Thus, using the long-form notation for |
@bcorso Thanks for the workaround. It does seem to work. Is there a workaround for the case where the chain of inheritance is deeper - e.g. building upon @AlekseyMiheev's example: and So the complete chain is: |
@bcorso workaround works for me, thanks. I'm wondering if this case is mentioned somewhere in release notes, documentation, etc. I think we can close this issue as workaround works. |
@Zhelyazko, for deeper inheritance you can use the same workaround for each base class, i.e. both @AlekseyMiheev, I'll be submitting a fix to avoid having to use the workaround (i.e. you should be able to use the short-form of the annotation everywhere). The workaround isn't mentioned in the release notes/documentation because it was more of an oversight than something we intended. I can close out this issue once that fix is submitted. |
I think it's smart if you can use
and when you have
You wouldn't have to do
|
I'm experiencing a similar issue but I make use of a BasFragment which takes a generic type T , none of the hacks work for me (T is meant to be a generated binding class) |
@dewunmi can you post the code that isn't working for you, and what failure you are getting? |
@Crazylegend, the reason you can't just annotate the base class is because Dagger needs the exact type when doing members injection (See "a note about covariance" section). For each Injecting |
…en using plugin. This fixes a bug when using the plugin where the child generated class uses `@Overrides void inject()` which fails because that method doesn't exist in an ancestor until after bytecode injection. Fixes #1910 RELNOTES=Fix #1910: Allow usage of an @androidentrypoint base class when using short-form notation with the hilt gradle plugin. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=316891087
…en using plugin. This fixes a bug when using the plugin where the child generated class uses `@Overrides void inject()` which fails because that method doesn't exist in an ancestor until after bytecode injection. Fixes #1910 RELNOTES=Fix #1910: Allow usage of an @androidentrypoint base class when using short-form notation with the hilt gradle plugin. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=316891087
…en using plugin. This fixes a bug when using the plugin where the child generated class uses `@Overrides void inject()` which fails because that method doesn't exist in an ancestor until after bytecode injection. Fixes #1910 RELNOTES=Fix #1910: Allow usage of an @androidentrypoint base class when using short-form notation with the hilt gradle plugin. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=316891087
@bcorso
I wish I could do the workaround instead but for my case FragmentA : BaseFragmentB: BaseFragmentC, -BaseFragmentB uses some variables and methods from BaseFragmentC, having done the workaround BaseFragmentB : Hilt_BaseFragmentB wouldn't work. |
@TheGabCode Can you reproduce this with a minimal example and post here?
Can you check the generated class, |
I checked the generated class I have this subclass and the following super classes
but right, turns out I was misusing the long-term notation, so this might be non-issue for now. Thanks for the clarification with using the long-term notation. |
is this fix released? |
@qrezet, it should be fixed in the latest release, 2.28.3. |
Sorry for resurrecting this but I just wanted to double check if there is any way around my similar issue. I have I'm getting Is there any way for me to annotate the service for injection? |
It sounds like you don't have the Hilt Gradle plugin applied to you library. In particular, without the plugin you would need
With the plugin, you can extend
|
Thx for the reply, I was already using the Hilt Gradle Plugin and still getting that error, that's why I was a bit worried that there wouldn't be a way around it. But looks like it was a caching issue of some sort and now it's working as expected. |
Compilation fails for the next code:
Compilation error:
Method from the class where the error occurs:
Possible problem:
Hilt_CreateNoteFragment is generated for CreateNoteFragment class
Hilt_EditNoteFragment is generated for EditNoteFragment class
Hilt_EditNoteFragment extends CreateNoteFragment that doesn't have inject() method
The text was updated successfully, but these errors were encountered: