-
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
error: <identifier> expected topLevelClass = BaseFragment<T, D>.class #2042
Comments
Hey @ayoubdevv, Thanks for reporting this issue! This is definitely a bug on our end. We shouldn't be including the type parameters in In the mean time, you should be able to work around this issue by putting the // Put the annotation here instead of on the base class.
@AndroidEntryPoint
class MyFragment: BaseFragment<MyViewModel, MyViewDataBinding>() {
...
} |
thanks @bcorso for reply i'll try it but what about injecting ViewModel when using by viewModels() extension ** it says : thanks in Advanced @bcorso |
I think this is just a restriction of Kotlin? Is this a pattern you were using before Hilt? Edit: I know very little Kotlin, so happy to be proven wrong on this. |
i just used like documentation here |
Thinking about this more, I think we need to ban I'll fix the original bug, and then add a better error message to make it clear this isn't allowed. Details: |
@bcorso what about this workaround when we can use it ?
|
That should work out of the box already, but the usage above is not quite right. If you're using the Hilt Gradle plugin you would just do this: @AndroidEntryPoint
class ExampleFragment extends BaseFragment<FragmentExampleBinding>() |
Yes it working when removing @androidentrypoint from BaseFragment and put in subclass but base classes with type parameters we need it will be fixed or ban forever , because i used to use Dagger 2 and was work perfectly |
…asses with type parameters. This CL fixes a bug with OriginatingElementProcessor to change this: @OrginatingElement(topLevelElement=Foo<T>.class) To this: @OrginatingElement(topLevelElement=Foo.class) In addition, this CL bans @androidentrypoint usage on classes with type parameters. We're banning classes with type parameters because we can't generate an injector entry point for them (e.g. inject(FooActivity<T> fooActivity)) since the component itself doesn't have type parameters. Instead, our advice will be to use `@AndroidEntryPoint` on the non-parameterized subclasses instead. RELNOTES=Fix #2042: Fix bug in OriginatingElementProcessor and bans @androidentrypoint classes with type parameters. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=327049118
…asses with type parameters. This CL fixes a bug with OriginatingElementProcessor to change this: @OrginatingElement(topLevelElement=Foo<T>.class) To this: @OrginatingElement(topLevelElement=Foo.class) In addition, this CL bans @androidentrypoint usage on classes with type parameters. We're banning classes with type parameters because we can't generate an injector entry point for them (e.g. inject(FooActivity<T> fooActivity)) since the component itself doesn't have type parameters. Instead, our advice will be to use `@AndroidEntryPoint` on the non-parameterized subclasses instead. RELNOTES=Fix #2042: Fix bug in OriginatingElementProcessor and bans @androidentrypoint classes with type parameters. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=327049118
@ayoubdevv @bcorso
and
thats work for me |
@ghozimahdi not work for me |
@bcorso I can't use this work around if using multi-modules. I put BaseFragment in :base module. And other features module will implement this :base. And it will throw "failed to analyze: java.lang.reflect.InvocationTargetException" at compile time. Any updates on this? |
The update is in #2042 (comment)
By "multi-modules" do you mean you are using dynamic feature modules? If so, you're correct that you can't use Hilt in such a way. The guidance is explained in https://developer.android.com/training/dependency-injection/hilt-multi-module#dfm. If you just mean normal Gradle modules, it shouldn't matter if |
I just used normal android library modules. I created a sample that reproduce error: https://github.com/8991hnim/Hilt-Multi-Modules-Sample Module's relation: When run will get compile errors. Please take a look at the repository. Thank you. |
@bcorso it's been 1 week. Please give me some updates. I'm stuck :( |
@8991hnim it's likely that this is due to missing transitive dependencies in the classpath during compilation. Hilt has the aggregating task flag to fix these issues automatically. Can you try enabling the flag by adding the following in your application's
|
Something else must be going on, looking at @8991hnim's repro app, the processor is crashing with the following trace:
|
Thanks, it works 💯 |
still its not working........ |
Please, solve the issue of injecting abstract class parameters : abstract class BaseFragment<VM : ViewModel, viewBinding : ViewDataBinding, repository : BaseRepository> : Fragment(){} Everything was working fine when I was using dagger2 but having issues with using Hilt. |
Hi Everybody, So I mentioned this yesterday on stackoverflow here
i Have issues when try to use inject ViewModel to BaseFragment with by viewModels() extension so i used Factory to inject it
when i do that my BaseFragment Have tow generic type and it show me that error
error: expected
topLevelClass = BaseFragment<T, D>.class
^error: [Hilt]
and the Generated Class is BaseFragment_GeneratedInjector :
so i try this workgound in this issues
and it show same error and new Error says :
**```
[Hilt] Processing did not complete. See error above for details.error: [Hilt]
@androidentrypoint class expected to extend Hilt_ContactUsFragment. Found: BaseFragment
The text was updated successfully, but these errors were encountered: