Hasactivityinjector Can Not Be Resolved In Android Dagger 2
Solution 1:
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.
Solution 2:
It's pretty late to answer but it might be useful for someone who is new to dagger world!
Its been replaced with HasAndroidInjector in order to avoid boilerplate of implementing multiple Dagger Interfaces like HasActivityInjector, HasServiceInjector etc, in your Application class. Now you only need to implement HasAndroidInjector like below:
classDaggerExampleApplication : Application(), HasAndroidInjector{
@Injectlateinitvar androidInjector : DispatchingAndroidInjector<Any>
overridefunandroidInjector(): AndroidInjector<Any> = androidInjector
overridefunonCreate() {
super.onCreate()
//Your code
}
}
Solution 3:
In addition to @mbonnin and @Subhan's answer, starting version 2.24, Has{Activity,Fragment,Service,ContentProvider,BroadcastReceiver}
are removed.
If you still want to support this old implementation, use version 2.23 which supports both HasAndroidInjector
and Has{Activity,Fragment,Service,ContentProvider,BroadcastReceiver}
.
here's what it should look like on version 2.24
Application
classExampleApp: Application(), HasAndroidInjector {
@Injectlateinitvar androidInjector: DispatchingAndroidInjector<Any>
overridefunandroidInjector(): AndroidInjector<Any> = androidInjector
/..../
Activity
classExampleActivity: AppCompatActivity(), HasAndroidInjector {
@Injectlateinitvar androidInjector: DispatchingAndroidInjector<Any>
overridefunandroidInjector(): AndroidInjector<Any> = androidInjector
/..../
Fragment
classMoreFragment: Fragment(), HasAndroidInjector {
@Injectlateinitvar androidInjector: DispatchingAndroidInjector<Any>
overridefunandroidInjector(): AndroidInjector<Any> = androidInjector
/..../
Solution 4:
My dependencies looks like this:
//Dagger
implementation "com.google.dagger:dagger:${libs.dagger}"
implementation "com.google.dagger:dagger-android:${libs.dagger}"
implementation "com.google.dagger:dagger-android-support:${libs.dagger}"
kapt "com.google.dagger:dagger-compiler:${libs.dagger}"
kapt "com.google.dagger:dagger-android-processor:${libs.dagger}"
The support
one is needed if you're using appcompat.
And the ${libs.dagger}
refers to the needed dagger version (e.g. 2.16).
Read more about dependencies here.
Solution 5:
Could have been late late answer but new Dagger2 dependencies carries DaggerAppCompatActivity
and DaggerFragment
classes which are useful for injecting activities and fragments by itself. So, we no longer need HasActivityInjector
, autoInjection methods or something like them.
Post a Comment for "Hasactivityinjector Can Not Be Resolved In Android Dagger 2"