错误:找不到符号@dagger.hilt.InstallIn(value={ApplicationComponent.class})

升级匕首柄后(版本:2.31-alphaApplicationComponent.class无法找到。Component类似 RoomDatabase的替代方案是什么?

@Module
@InstallIn(ApplicationComponent::class)
class RoomModule() {
private val DATABASE_NAME = "salat_time"

@Singleton
@Provides
fun provideRoomDatabase(@ApplicationContext appContext: Context) = Room.databaseBuilder(
    appContext,
    AppDatabase::class.java,
    DATABASE_NAME
).createFromAsset("db/$DATABASE_NAME.sqlite").build()

@Singleton
@Provides
fun provideLocalSalatRepository(database: AppDatabase) = LocalSalatRepository(database)

@Singleton
@Provides
fun provideDistrictRepository(database: AppDatabase) = DistrictRepository(database)
}

回答

ApplicationComponent在 Dagger 版本2.30 中 已弃用,
ApplicationComponent在 Dagger 版本2.31 中 删除
或者SingletonComponent应该使用代替ApplicationComponent

@Module
@InstallIn(SingletonComponent::class)
class RoomModule() {
   . . .
}

  • **Note:** For those who are still unable to find `SingletonComponent` while importing, it is in `dagger.hilt.components.SingletonComponent` package. All other `Components` are in `dagger.hilt.android.components` package.

回答

ApplicationComponent更名为SingletonComponent


以上是错误:找不到符号@dagger.hilt.InstallIn(value={ApplicationComponent.class})的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>