【发布时间】:2020-12-11 22:17:14
【问题描述】:
我是 Android 依赖注入的新手。我正在使用 Dagger-Hilt,在为 DB 提供程序生成的 AppModule 类中出现错误并且项目无法编译。
错误是@InstallIn can only be used on @Module or @EntryPoint classes
这是我的 AppModule 对象。我在哪里犯错了?
@Module
@InstallIn(ApplicationComponent::class)
object AppModule {
@Singleton
@Provides
fun provideAppDatabase(
@ApplicationContext app: Context
) = Room.databaseBuilder(
app,
AppDatabase::class.java,
"gelirkenal"
).build()
@Singleton
@Provides
fun provideItemDao(db: AppDatabase) = db.itemDao()
}
【问题讨论】:
-
你找到解决办法了吗?
-
仍未找到解决方案?我的问题:@InstallIn,只能和@DefineComponent一起使用——带注释的类
标签: android kotlin dagger dagger-hilt