question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@AndroidEntryPoint-annotated classes cannot have type parameters.

See original GitHub issue

@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

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:16

github_iconTop GitHub Comments

2reactions
Archerkillscommented, May 12, 2022

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.

1reaction
bcorsocommented, May 13, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

<identifier> expected android Hilt - kotlin - Stack Overflow
You can fix this by moving @AndroidEntryPoint from abstract class with parameters into child class without type parameters.
Read more >
java/dagger/hilt/android/processor/internal/androidentrypoint ...
"@%s-annotated classes cannot have type parameters.",. annotationClassName.simpleName());. final TypeElement androidEntryPointClassValue = Processors.
Read more >
Dependency injection with Hilt | Android Developers
... Work with observable data objects · Generated binding classes · Binding adapters ... Type safe navigation with Compose · Interact programmatically ...
Read more >
Migrating to Hilt - Dagger
All @Module classes should be annotated with @InstallIn . ... used to either add inject methods or get access to types like bindings...
Read more >
View model has no zero arg constructor when using ...
class ); // crashes ? An activity, a fragment? Is it annotated with @AndroidEntryPoint ? Would be great if you have a sample...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found