dagger: @AndroidEntryPoint-annotated classes cannot have type parameters.

@AndroidEntryPoint abstract class BaseFragment<VM : ViewModel, viewBinding : ViewDataBinding, repository : BaseRepository> : Fragment() { protected lateinit var binding: viewBinding protected lateinit var viewModel: VM var remoteDataSource = RemoteDataSource() ..................................... }

the error code image

About this issue

Most upvoted comments

The solution is to put the @AndroidEntryPoint annotation on each of your subclasses instead of the base class, e.g.

This solves the compile error for me. But if I remove @AndroidEntryPoint from base class, the @Inject fields in base class will NOT BE SET. Is it a known issue? Do we have plan to support it?

It’s a valid cases where both base class and child class have injected fields.

I initially concluded that this wasn’t possible (https://github.com/google/dagger/issues/2042#issuecomment-673252618) since we couldn’t implement the inject() method. However, thinking about it more we can probably support it similar to the workaround I suggested above as long as the generic base class is abstract.

In particular, the generated Hilt_MiddleView class wouldn’t actually implement inject(), it would just add the abstract inject() method and the constructor call for you, just like you’re currently doing manually.

I think this should be a pretty easy thing for us to fix.

I have tried this solution was still have problems.