【发布时间】:2021-05-23 19:41:38
【问题描述】:
我正在尝试在此处遵循 Hilt 迁移指南: https://dagger.dev/hilt/migration-guide.html
并用以下注释注释了我的所有模块:
@InstallIn(SingletonComponent::class)
但是,我的服务、片段和活动的“贡献者”模块遇到了问题。
每个模块都有一个,
@Module
@InstallIn(SingletonComponent::class)
abstract class FragmentContributorModule {
@ContributesAndroidInjector
internal abstract fun contributeMyFragment(): MyFragment
}
@Module
@InstallIn(SingletonComponent::class)
abstract class ActivityContributorModule {
@ContributesAndroidInjector
internal abstract fun contributeMyActivity(): MyActivity
}
@Module
@InstallIn(SingletonComponent::class)
abstract class ServiceContributorModule {
@ContributesAndroidInjector
internal abstract fun contributeMyService(): MyService
}
在编译期间,每个“贡献”函数都会出错:
com.test.ActivityContributorModule_ContributeMyActivity$defaultsDebug is missing an @InstallIn annotation. If this was intentional, see https://dagger.dev/hilt/compiler-options#disable-install-in-check for how to disable this check.
我还尝试对每个模块使用 ServiceComponent::class、FragmentComponent::class 和 ActivityComponent::class,但没有成功。我正在尝试分段迁移项目,因此我认为在所有内容都升级到 Hilt 之前我无法删除这些项目。
有什么想法吗?
【问题讨论】:
-
曾经尝试将它们放入单独的文件中吗?
-
上面的每个模块都在一个单独的文件中。
标签: android dagger-2 dagger-hilt