Dagger Hilt abstract class with types

Viewed 2319

Hello everyone I am trying to use Dagger-Hilt and I am wondering how is it possible to achieve this code bellow?

@AndroidEntryPoint
abstract class BaseActivity <B : ViewDataBinding, VM : ViewModel> : IActivity<VM>, AppCompatActivity() {

   @Inject
   lateinit var someClass: SomeClass
}

Gradle returns this error:

 BaseActivity_GeneratedInjector.java:10: error: <identifier> expected
    topLevelClass = BaseActivity<B, VM>.class
                                        ^error: [Hilt]
  class java.lang.NullPointerException: java.lang.NullPointerException

This is the generated Java class:

@OriginatingElement(
    topLevelClass = BaseActivity<B, VM>.class
)
@GeneratedEntryPoint
@InstallIn(ActivityComponent.class)
@Generated("dagger.hilt.android.processor.internal.androidentrypoint.InjectorEntryPointGenerator")
public interface BaseActivity_GeneratedInjector {
  void injectBaseActivity(BaseActivity baseActivity);
}

Help will be greatly appreciated.

1 Answers

As I understand this is bug inside Hilt.

Check related github issue: https://github.com/google/dagger/issues/2042

You can fix this by moving @AndroidEntryPoint from abstract class with parameters into child class without type parameters.

Related