Ema*_*nho 11 android dependency-injection kotlin dagger-2 androidx
我正在使用Dagger 2.21,而当我尝试这样做时
@Module
internal abstract class FragmentModule {
@ContributesAndroidInjector
internal abstract fun loginFragment() : LoginFragment
}
Run Code Online (Sandbox Code Playgroud)
和
@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>()
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
/app/build/generation/source/kapt/debug/com/photoco/app/injection/module/FragmentModule_LoginFragment$app_debug.java:18:错误:不兼容的类型:类LoginFragment无法转换为类扩展Fragment
我一直在搜索,发现使用2.21并将其设置为可以正常工作,但还没有运气
android.useAndroidX = true; android.enableJetifier = true
LoginFragment扩展:
dagger.android.support.DaggerFragment()
由于所有这些设置无法构建,我在这里缺少什么吗?我可以使用DaggerActivity使其与Activity一起使用,但不能与Fragments一起使用。
PhotocoApplication扩展了dagger.android.support.DaggerApplication
谢谢!
Ema*_*nho 19
通过将所有匕首依赖项更新为2.21,修复了此问题,缺少了android-support(仍在使用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"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1381 次 |
| 最近记录: |