I'm using Dagger2 for DI in android app,
I want inject viewModel in a fragment by AndroidInjector
and have this two line :
AndroidInjection.inject(this)
viewModel = ViewModelProviders.of(this, viewModelFactory).get(ProductDetailViewModel::class.java)
When my fragment extends androidx.fragment.app.Fragment
shows this error:
android.support.v4.app.Fragment
android.app.Fragment
now I don't know my fragment should extends which one!
I get this error when choose one of them :
None of the following functions can be called with the arguments supplied:
public open fun inject(activity: Activity!): Unit defined in dagger.android.AndroidInjection
public open fun inject(fragment: Fragment!): Unit defined in dagger.android.AndroidInjection
public open fun inject(service: Service!): Unit defined in dagger.android.AndroidInjection
public open fun inject(contentProvider: ContentProvider!): Unit defined in dagger.android.AndroidInjection
My mistake was using dagger-android (not dagger-android-support), and dagger-android just has :
AndroidInjection.inject(this)
but I should use
AndroidSupportInjection.inject(this)
that is in supportLibrary version of dagger-android that named dagger-android-support