Dagger 2 androidx 片段不兼容类型

Dagger 2 androidx fragment incompatible types

我正在使用 Dagger 2.21,当我尝试这样做时

@Module
internal abstract class FragmentModule {
    @ContributesAndroidInjector
    internal abstract fun loginFragment() : LoginFragment
}

@Singleton
@Component(modules = [AndroidSupportInjectionModule::class, AppModule::class, ActivityModule::class, ViewModelBuilder::class, ViewModelModule::class, RepositoriesModule::class, ApiModule::class, FragmentModule::class])
interface AppComponent : AndroidInjector<PhotocoApplication> {
    @Component.Builder
    abstract class Builder : AndroidInjector.Builder<PhotocoApplication>()
}

我收到此错误:

/app/build/generated/source/kapt/debug/com/photoco/app/injection/module/FragmentModule_LoginFragment$app_debug.java:18: error: incompatible types: Class LoginFragment cannot be converted to Class extends Fragment

我一直在搜索并看到使用 2.21 并设置它可以正常工作,但还没有成功

android.useAndroidX=true ; android.enableJetifier=true

LoginFragment 扩展:

dagger.android.support.DaggerFragment()

所有这些设置都无法构建,我是不是漏掉了什么?我可以使用 DaggerActivity 使其与 Activity 一起使用,但不能与 Fragments 一起使用。

PhotocoApplication 扩展 dagger.android.support.DaggerApplication

谢谢!

通过将所有 Dagger 依赖项更新为 2.21 解决了这个问题,缺少 android-支持(仍在使用 2.16)。

implementation 'com.google.dagger:dagger:2.21'
implementation 'com.google.dagger:dagger-android:2.21'
implementation 'com.google.dagger:dagger-android-support:2.21'
kapt "com.google.dagger:dagger-compiler:2.21"
kapt "com.google.dagger:dagger-android-processor:2.21"

我遇到了同样的问题,但有两个 non-Android classes:EventBus 和 Android 资源的包装器 class。

我尝试了 Emanuel Amiguinho 提出的解决方案,即使它与 android-support 无关,但它已得到修复。于是尝试去掉添加的依赖重试,神奇地再次构建成功

所以我猜我的情况是缓存问题。