error: cannot find symbol @dagger.hilt.InstallIn(value = {ApplicationComponent.class})
error: cannot find symbol @dagger.hilt.InstallIn(value = {ApplicationComponent.class})
升级后匕首柄(版本:2.31-alpha
)ApplicationComponent.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() {
. . .
}
ApplicationComponent 重命名为 SingletonComponent
除了已接受的答案外,请务必更新到 latest 刀柄版本,否则您将卡在 KaptExecution Error.
当前版本ext.hilt_version = '2.33-beta'
只需导入:
import dagger.hilt.components.SingletonComponent
并将您的模块注释为:
@Module
@InstallIn(SingletonComponent::class)
因为 ApplicationComponent 在较新版本的 daggerHilt 中被删除,我在应用级别 gradle 文件中将这些依赖项用于匕首柄:
//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.31-alpha"
kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0"
如果您不需要@InstallIn,您可以随时明确禁用。
Alternatively, the check can be disabled at the individual module level by annotating the module with @DisableInstallInCheck.
如https://dagger.dev/hilt/flags.html
所述
喜欢
@DisableInstallInCheck
@Module
class MyAwesomeModule
升级后匕首柄(版本:2.31-alpha
)ApplicationComponent.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() {
. . .
}
ApplicationComponent 重命名为 SingletonComponent
除了已接受的答案外,请务必更新到 latest 刀柄版本,否则您将卡在 KaptExecution Error.
当前版本ext.hilt_version = '2.33-beta'
只需导入:
import dagger.hilt.components.SingletonComponent
并将您的模块注释为:
@Module
@InstallIn(SingletonComponent::class)
因为 ApplicationComponent 在较新版本的 daggerHilt 中被删除,我在应用级别 gradle 文件中将这些依赖项用于匕首柄:
//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.31-alpha"
kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0"
如果您不需要@InstallIn,您可以随时明确禁用。
Alternatively, the check can be disabled at the individual module level by annotating the module with @DisableInstallInCheck.
如https://dagger.dev/hilt/flags.html
所述喜欢
@DisableInstallInCheck
@Module
class MyAwesomeModule