I got the same error when I wanted to implement Room + Hilt in the same project. So to solve this, you have to add inside your libs.versions.toml file:
[versions]
#Android
gradle = "8.5.2"
#Kotlin
kotlin = "2.0.20"
#Ksp
devtoolsKsp = "2.0.20-1.0.24"
#Hilt
hiltAndroid = "2.52"
#Libraries
composeBom = "2024.08.00"
compose = "1.5.15"
navigationCompose = "1.2.0"
room = "2.6.1"
[plugins]
android-application = { id = "com.android.application", version.ref = "gradle" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
devtools-ksp = { id = "com.google.devtools.ksp", version.ref = "devtoolsKsp" }
hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hiltAndroid" }
[libraries]
compose-bom = { module = "androidx.compose:compose-bom", version.ref = "composeBom" }
compose-material = { module = "androidx.compose.material:material" }
room-runtime = { module = "androidx.room:room-runtime", version.ref = "room" }
room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" }
room-compiler = { module = "androidx.room:room-compiler", version.ref = "room" }
hilt = { module = "com.google.dagger:hilt-android", version.ref = "hiltAndroid" }
hilt-compiler = { module = "com.google.dagger:hilt-compiler", version.ref = "hiltAndroid" }
hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "navigationCompose" }
And inside the build.gradle (Project file):
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.devtools.ksp) apply false
alias(libs.plugins.hilt.android) apply false
}
And inside the build.gradle (Module file):
dependencies {
//Compose
implementation(platform(libs.compose.bom))
implementation(libs.compose.material)
//Room
implementation(libs.room.runtime)
implementation(libs.room.ktx)
ksp(libs.room.compiler)
//Hilt
implementation(libs.hilt)
ksp(libs.hilt.compiler)
//Hilt Navigation Compose
implementation(libs.hilt.navigation.compose)
}
Make also sure to use:
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
And add the plugins at the beginning of the file:
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.devtools.ksp)
alias(libs.plugins.hilt.android)
}