Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
}
like image 702
Mostasim Billah Avatar asked Feb 01 '21 06:02

Mostasim Billah


3 Answers

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() {
   . . .
}
like image 132
Mostasim Billah Avatar answered Oct 23 '22 03:10

Mostasim Billah


ApplicationComponent is renamed to SingletonComponent

like image 22
Ercan Avatar answered Oct 23 '22 03:10

Ercan


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"
like image 10
Ali Nawaz Avatar answered Oct 23 '22 01:10

Ali Nawaz