How to inject a fragment from the package androidx.fragment.app.Fragment ?
I\'m using the dagger-android framework to inject my dependencies in
The solution to my particular problem was to use android dagger classes as interfaces instead of extend of them:
class MyFragment() : HasSupportFragmentInjector {
@Inject
lateinit var childFragmentInjector: DispatchingAndroidInjector
override fun onAttach(context: Context?) {
AndroidSupportInjection.inject(this)
super.onAttach(context)
}
override fun supportFragmentInjector(): AndroidInjector {
return childFragmentInjector
}
........
}
To my Activities
class MyActivity : HasSupportFragmentInjector {
@Inject
internal lateinit var fragmentInjector: DispatchingAndroidInjector
override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
super.onCreate(savedInstanceState)
}
override fun supportFragmentInjector(): AndroidInjector = fragmentInjector
...... }
and also I have this in my gradle.properties file:
android.useAndroidX = true android.enableJetifier = true