Closed ckdrb7017 closed 4 years ago
I think you are using an old version of Dagger Android, as HasActivityInjector
had been removed in 2.24, try with the latest one as the docs, that you may follow are updated as well
Yes, HasActivityInjector is part of dagger-android, which is a different dependency injection method than Dagger2 and is deprecated. I have jumped back to Dagger 2, which does not use the : AndroidInjector class. Which packages are you importing? You have to watch out for "dagger-android" and remove the imports wherever they pop up.
Two things:
Closing this since it sounds like this issue is fixed by changing to the new HasAndroidInjector. Please let me know if this isn't the case though, thanks.
I am studying Dagger2 now. I am studying by looking at several examples. But there are some parts that aren't working properly, looking at the examples. I know that the structure of Dagger2 should be defined and implemented in the order of application -> active -> user component. However, an error occurred when following this. the message is java.lang.RuntimeException: android.app.Application does not implement dagger.android.HasActivityInjector The code is long, but I wish someone would show up to help me. I am very desperate.
AppComponent @Singleton @Component(modules = [AndroidSupportInjectionModule::class, ActivityBindingModule::class, ApplicationModule::class]) interface AppComponent : AndroidInjector {
}
BaseApplication class BaseApplication : DaggerApplication() { override fun applicationInjector(): AndroidInjector {
return DaggerAppComponent.builder().application(this).build()
}
}
ActivityScope @Scope annotation class ActivityScope
ActivityBindingModule @Module abstract class ActivityBindingModule {
}
MainModule @Module class MainModule { @ActivityScope @Provides fun util() : Utils = Utils()
}
ApplicationModule @Module class ApplicationModule { @Provides fun providesContext(application: Application): Context { return application } }
Utils class Utils { @Inject constructor(){ } fun add(a :Int, b:Int):Int= a+b fun sub(a :Int, b:Int):Int= a-b fun div(a :Int, b:Int):Int= a/b fun mul(a :Int, b:Int):Int= a*b
}
MainActivity class MainActivity : DaggerAppCompatActivity(), HasActivityInjector {
}