Search code examples
androidkotlinandroid-roomdagger-hilt

error: [Hilt] @InstallIn, 'value' class is invalid or missing: @dagger.hilt.InstallIn({}) [Hilt] Processing did not complete.?


I am developing new android app but when I run I am getting following error

*> Task :app:kaptDebugKotlin
        error: [Hilt]
          @InstallIn, 'value' class is invalid or missing: @dagger.hilt.InstallIn({})
          [Hilt] Processing did not complete. See error above for details.
        C:\Users\Yodgorbek\AndroidStudioProjects\StockMarketApp\app\build\tmp\kapt3\stubs\debug\com\example\stockmarketapp\data\local\StockDatabase.java:7: warning: Schema export directory is not provided to the annotation processor so we cannot export the schema. You can either provide `room.schemaLocation` annotation processor argument OR set exportSchema to false.
        public abstract class StockDatabase extends androidx.room.RoomDatabase {
                        ^
        [Hilt]*

below AppModule.kt

import android.app.Application
import androidx.room.Room
import com.example.stockmarketapp.data.local.StockDatabase
import com.example.stockmarketapp.data.remote.StockApi
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import retrofit2.create
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object AppModule {
    @Provides
    @Singleton
    fun provideStockApi(): StockApi {
        return Retrofit.Builder()
            .baseUrl(StockApi.BASE_URL)
            .addConverterFactory(MoshiConverterFactory.create())
            .build()
            .create()

    }

    @Provides
    @Singleton
    fun provideStockDatabase(app: Application): StockDatabase {
        return Room.databaseBuilder(
            app,
            StockDatabase::class.java,
            "stockdb.db"
        ).build()

    }
}

below StockDatabase.kt class where error occuring

import androidx.room.Database
import androidx.room.RoomDatabase

@Database(
    entities = [CompanyListingEntity::class],
    version = 1
)
abstract class StockDatabase:RoomDatabase() {
    abstract val dao:StockDao
}

below app.gradle

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
    id 'kotlin-parcelize'
    id 'com.google.devtools.ksp' version '1.6.10-1.0.2'
}
kotlin {
    sourceSets {
        debug {
            kotlin.srcDir("build/generated/ksp/debug/kotlin")
        }
        release {
            kotlin.srcDir("build/generated/ksp/release/kotlin")
        }
    }
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.stockmarketapp"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_version
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.4.0'
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'

    // OpenCSV
    implementation 'com.opencsv:opencsv:5.5.2'

    // Compose dependencies
    implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.4.1"
    implementation "androidx.compose.material:material-icons-extended:$compose_version"
    implementation "com.google.accompanist:accompanist-flowlayout:0.17.0"
    implementation 'androidx.paging:paging-compose:1.0.0-alpha15'
    implementation "androidx.activity:activity-compose:1.6.0-alpha03"
    implementation "com.google.accompanist:accompanist-swiperefresh:0.24.2-alpha"

    // Compose Nav Destinations
    implementation 'io.github.raamcosta.compose-destinations:core:1.1.2-beta'
    ksp 'io.github.raamcosta.compose-destinations:ksp:1.1.2-beta'

    // Coil
    implementation "io.coil-kt:coil-compose:1.4.0"

    //Dagger - Hilt
    implementation 'com.google.dagger:hilt-android:2.42'
    kapt 'com.google.dagger:hilt-android-compiler:2.42'
    implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
    kapt "androidx.hilt:hilt-compiler:1.0.0"
    implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'

    // Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-moshi:2.9.0'
    implementation "com.squareup.okhttp3:okhttp:5.0.0-alpha.3"
    implementation "com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.3"

    // Room
    implementation "androidx.room:room-runtime:2.4.2"
    kapt "androidx.room:room-compiler:2.4.2"

    // Kotlin Extensions and Coroutines support for Room
    implementation "androidx.room:room-ktx:2.4.2"
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}

below build.gradle

buildscript {
    ext {
        compose_version = '1.1.0-beta01'
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.2.0' apply false
    id 'com.android.library' version '7.2.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
    id 'com.google.dagger.hilt.android' version '2.42' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

what I have tried updated latest version of room and dagger hilt in app.gradle dependencies tried following link error: cannot find symbol @dagger.hilt.InstallIn(value = {ApplicationComponent.class}) all other stackoverflow links as well I have changed jdk version from android studio it did not help I want to know where I am making mistake


Solution

  • I solved problem by adding InstallIn annotation to repoModule and by removing following implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03" hilt dependcy