'error: cannot find symbol @dagger.hilt.InstallIn(value = {ApplicationComponent.class})
After upgrading dagger hilt(version: 2.31-alpha) ApplicationComponent.class can not find.
What is the alternative for a Component like 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)
}
Solution 1:[1]
ApplicationComponent is Deprecated in Dagger Version 2.30 ApplicationComponent removed in Dagger Version 2.31
Alternatively SingletonComponent should be used instead of ApplicationComponent
@Module
@InstallIn(SingletonComponent::class)
class RoomModule() {
. . .
}
Solution 2:[2]
ApplicationComponent is renamed to SingletonComponent
Solution 3:[3]
Just import:
import dagger.hilt.components.SingletonComponent
and annotate your module as:
@Module
@InstallIn(SingletonComponent::class)
Because ApplicationComponent is removed in the newer version of daggerHilt and I'm using these dependencies for dagger hilt within app level gradle file:
//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"
Solution 4:[4]
In addition to the accepted answer, please be sure to update to the latest hilt version, or else you will be stuck with KaptExecution Error.
Current version ext.hilt_version = '2.33-beta'
Solution 5:[5]
If you do not need @InstallIn, you can always disable explicitly.
Alternatively, the check can be disabled at the individual module level by annotating the module with @DisableInstallInCheck.
As mentioned in https://dagger.dev/hilt/flags.html
Like
@DisableInstallInCheck
@Module
class MyAwesomeModule
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mostasim Billah |
| Solution 2 | Ercan |
| Solution 3 | Ali Nawaz |
| Solution 4 | Max |
| Solution 5 | theAshutoshAJ |
