Getting issue dependency was found while adding dagger hilt
Asked Answered
S

1

1

I am running a project with Jetpack Compose. And I'm using Kotlin DSL. And I added the dagger hilt to my project and I'm having an issue with the project.

java.lang.IllegalStateException: The Hilt Android Gradle plugin is applied but no com.google.dagger:hilt-android dependency was found.

dagger-hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
devtools-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }

hilt version is 2.44 or 2.51.1 and 1.9.20-1.0.14 I tried with the difffent version of ksp also.

Add plugin on main build.gradle.kts

alias(libs.plugins.dagger.hilt.android) apply false
alias(libs.plugins.devtools.ksp) apply false

Add plugin on the app build.gradle.kts

alias(libs.plugins.devtools.ksp)
alias(libs.plugins.dagger.hilt.android) // If I add this in a plugin I'm getting the error.

When I'm building the project getting issues

A problem occurred configuring project ':app'. The Hilt Android Gradle plugin is applied but no com.google.dagger:hilt-android dependency was found.

And I follow those steps too - Dependency injection with Hilt

Salve answered 16/4, 2024 at 5:48 Comment(8)
Did you used Kapt or Ksp ?Tortilla
Ksp in the project and I already mention it aboveSalve
Hilt supoorts ksp from V2.4.8Tortilla
I already mentioned those above I was trying with hilt 2.51.1 too.Salve
You might missing dependency in build.gradle(aap) and also share your both gradle file app-level as well as project-levelNickelodeon
Add dependency is compulsory? I mean Just want to add plugin first then I will add the dependency. @ChiragThummarSalve
Yes, You need plugin in dependency both at same time. can you share more code please?Nickelodeon
I tried. And it works for me. I need to add the dependency at the same time while adding the plugins. @ChiragThummar Thank YouSalve
S
1

We need to add the dependency at the same time while adding plugins. It will not work with the adding plugins only. Thank you to Chirag Thummar

Add dependencies

hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }
hilt-android-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" }

Add bellow code on app level build.gradle.kts too.

dependencies {
    implementation(libs.hilt.android)
    ksp(libs.hilt.android.compiler)
}
Salve answered 17/4, 2024 at 7:10 Comment(1)
Good to see it worksNickelodeon

© 2022 - 2025 — McMap. All rights reserved.