I’m working on an Android project with Kotlin and using Dagger Hilt for dependency injection. Recently, I’ve attempted to migrate from kapt to KSP (Kotlin Symbol Processing) for code generation, as kapt is now in “maintenance mode”. However, I’ve run into an issue: Dagger Hilt annotations such as @Inject, @Binds, and @Module are not being detected by KSP, and I’m getting a “Cannot resolve symbol” error.
I was testing the connection to Supabase using the “Framework Quickstarts: Use Supabase with Android Kotlin” documentation, where you can find the code. My build.gradle.kts(module):
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android") version "1.9.20"
id ("com.google.relay") version "0.3.10"
kotlin("plugin.serialization") version "1.9.0"
id ("com.google.devtools.ksp") version "1.9.20-1.0.14"
}
android {
namespace = "xxxxxxxxxxx"
compileSdk = 34
defaultConfig {
applicationId = "xxxxxxxxxxxx"
minSdk = 24
targetSdk = 33
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = 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"
}
}
dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.10.0")
implementation(platform("io.github.jan-tennert.supabase:bom:1.4.6-dev-1"))
implementation("io.github.jan-tennert.supabase:postgrest-kt")
implementation("io.github.jan-tennert.supabase:realtime-kt")
implementation("io.github.jan-tennert.supabase:storage-kt")
implementation("io.github.jan-tennert.supabase:functions-kt")
implementation("io.github.jan-tennert.supabase:gotrue-kt")
implementation("io.github.jan-tennert.supabase:compose-auth")
implementation("io.github.jan-tennert.supabase:compose-auth-ui")
implementation("io.ktor:ktor-client-cio:2.3.5")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
ksp("com.google.dagger:dagger-compiler:2.48.1") // Dagger compiler
ksp("com.google.dagger:hilt-compiler:2.48.1") // Hilt compiler
ksp("androidx.room:room-compiler:2.6.0")
ksp("androidx.hilt:hilt-compiler:1.1.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}
My build.gradle.kts(proyect):
plugins {
id("com.android.application") version "8.1.2" apply false
id("org.jetbrains.kotlin.android") version "1.9.20" apply false
id("com.google.devtools.ksp") version "1.9.20-1.0.14" apply false
}
I’ve tried cleaning and rebuilding my project, verifying my dependency versions, and reviewing my Dagger Hilt and KSP setup. I’ve also reviewed the official KSP documentation and Google documentation as well, but I haven’t been able to resolve the issue. I expected that after migrating to KSP, Dagger Hilt annotations would be correctly detected and the code would work as expected.
I finally solve it, my mistake was not to write
at the dependencies from the build.gradle.kts (module). I also made some changes in the build.gradle files
now it completely works.
i leave my build.gradle.kts(module):
and my build.gradle.kts (proyect)