I am using Dagger Hilt in my project and I got this error message:
C:\Users\user\Desktop\Projeler\kotlin-coroutines-master\LOTRApp-master\app\build\generated\source\kapt\debug\com\example\lotr\BaseApplication_ComponentTreeDeps.java:23: error: cannot find symbol import hilt_aggregated_deps._com_example_lotr_presentation_BookListViewModel_HiltModules_BindsModule; ^ symbol: class _com_example_lotr_presentation_BookListViewModel_HiltModules_BindsModule location: package hilt_aggregated_deps
How can I fix it?
BaseApplication:
@HiltAndroidApp
class BaseApplication : Application() {
}
build.gradle(:app):
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id("dagger.hilt.android.plugin")
id("org.jetbrains.kotlin.plugin.serialization")
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.lotr"
minSdk 21
targetSdk 31
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'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.5.10'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
def lifecycle_version = "2.3.1"
def arch_version = "2.1.0"
def coroutines_version = "1.5.2"
def retrofit_version = "2.9.0"
def ktor_version = "1.6.3"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.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.3.1'
testImplementation 'junit:junit:4.+'
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"
// ViewModel
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
// LiveData
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version")
// Lifecycles only (without ViewModel or LiveData)
implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version")
// Saved state module for ViewModel
implementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version")
// Annotation processor
kapt("androidx.lifecycle:lifecycle-compiler:$lifecycle_version")
// alternately - if using Java8, use the following instead of lifecycle-compiler
implementation("androidx.lifecycle:lifecycle-common-java8:$lifecycle_version")
//Dagger Hilt
implementation("com.google.dagger:hilt-android:2.38.1")
kapt("com.google.dagger:hilt-android-compiler:2.38.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07")
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha03'
//Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
//Retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation("com.squareup.okhttp3:logging-interceptor:4.9.2")
//Ktor
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-android:$ktor_version"
implementation "io.ktor:ktor-client-serialization:$ktor_version"
implementation "io.ktor:ktor-client-logging:$ktor_version"
implementation "ch.qos.logback:logback-classic:1.2.3"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.0"
}
kapt {
correctErrorTypes = true
}
build.gradle(project):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
compose_version = '1.0.0'
}
repositories {
google()
mavenCentral()
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
classpath("com.google.dagger:hilt-android-gradle-plugin:2.38.1")
classpath("org.jetbrains.kotlin:kotlin-serialization:1.6.0-M1")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
BookListViewModel:
@HiltViewModel
class BookListViewModel @Inject constructor(
private val bookRepository: BookRepository
) : ViewModel(){
val state = mutableStateOf(BookListState())
init {
getBooks()
}
private fun getBooks() {
bookRepository.getBooks().onEach { result ->
when(result) {
is Resource.Success -> {
state.value = BookListState(books = result.data ?: emptyList())
}
is Resource.Error -> {
state.value = BookListState(error = result.message ?: "Unexpected Error")
}
is Resource.Loading -> {
state.value = BookListState(isLoading = true)
}
}
}.launchIn(viewModelScope)
}
}