HasActivityInjector can not be resolved in android dagger 2

Bajrang Hudda picture Bajrang Hudda · Oct 23, 2018 · Viewed 8k times · Source

I was trying to implement HasActivityInjector in my android application but it's showing me HasActivityInjector cann't be resolved. Below dependencies and plugin I have used in my project-

apply plugin: 'kotlin-kapt'

and

implementation 'com.google.dagger:dagger:2.16'
kapt 'com.google.dagger:dagger-compiler:2.16'

Here is the code I am trying -

class RanoBoilerplateApplication : Application(), HasActivityInjector{
    @Inject
    lateinit var activityDispatchingAndroidInjector:
            DispatchingAndroidInjector<Activity>

    override fun onCreate() {
        super.onCreate()

        DaggerAppComponent.builder()
                .application(this)
                .build()
                .inject(this)
    }

    override fun activityInjector(): AndroidInjector<Activity> =
            activityDispatchingAndroidInjector
}

I don't know what other dependencies I must have to include to work that, help me if anyone have done this before.

Find the latest Dagger 2 version here.

Happy coding :-)

Answer

mbonnin picture mbonnin · Aug 21, 2019

In case anyone comes here after updating to 2.24, this was removed: https://github.com/google/dagger/commit/3bd8f707cb28fd0c5f3abb4f87658566f8b52c10.

You can use HasAndroidInjector instead.