@InstallIn只能用于@Module或@EntryPoint类

我是 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()
}

回答

我将模块的导入设置如下:

import com.google.android.datatransport.runtime.dagger.Module

但以下是正确的:

import dagger.Module


以上是@InstallIn只能用于@Module或@EntryPoint类的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>