How to implement Hilt correctly?


I implemented Hilt and got this error: [ksp] [Hilt] Expected @AndroidEntryPoint to have a value. Did you forget to apply the Gradle Plugin? (com.google.dagger.hilt.android) .

When try to implement it in the plugins I get the error: Plugin with id 'com.google.dagger.hilt.android' was already requested at line 2 .

How did that happen and how can I solve it?

build.gradle.kts (Project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    alias(libs.plugins.android.application) apply false
    alias(libs.plugins.kotlin.compose) apply false
    alias(libs.plugins.kotlin.android) apply false

    // Room
    alias(libs.plugins.ksp) apply false

    // Hilt
    alias(libs.plugins.hilt) apply false
}

build.gradle.kts (app)

import com.android.aaptcompiler.compileResource

plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.kotlin.compose)
    // alias(libs.plugins.kotlin.android) ???
    alias(libs.plugins.ksp)
    //alias(libs.plugins.hilt) ???
}

android {
    namespace = "com.slatertechnologies.changebackgroundcolor"
    compileSdk {
        version = release(36) {
            minorApiLevel = 1
        }
    }

    defaultConfig {
        applicationId = "com.slatertechnologies.changebackgroundcolor"
        minSdk = 24
        targetSdk = 36
        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_11
        targetCompatibility = JavaVersion.VERSION_11
    }
    buildFeatures {
        compose = true
    }
}

dependencies {

    implementation(platform(libs.androidx.compose.bom))
    implementation(libs.androidx.activity.compose)
    implementation(libs.androidx.compose.material3)
    implementation(libs.androidx.compose.ui)
    implementation(libs.androidx.compose.ui.graphics)
    implementation(libs.androidx.compose.ui.tooling.preview)
    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.lifecycle.runtime.ktx)

    testImplementation(libs.junit)
    androidTestImplementation(platform(libs.androidx.compose.bom))
    androidTestImplementation(libs.androidx.compose.ui.test.junit4)
    androidTestImplementation(libs.androidx.espresso.core)
    androidTestImplementation(libs.androidx.junit)

    debugImplementation(libs.androidx.compose.ui.test.manifest)
    debugImplementation(libs.androidx.compose.ui.tooling)

    // Room
    ksp(libs.androidx.room.compiler)
    implementation(libs.androidx.room.runtime)

    // Hilt
    ksp(libs.hilt.compiler)
    implementation(libs.hilt.android)

}

libs.versions.toml

[versions]
agp = "9.2.1"
coreKtx = "1.18.0"
junit = "4.13.2"
junitVersion = "1.3.0"
espressoCore = "3.7.0"
lifecycleRuntimeKtx = "2.10.0"
activityCompose = "1.13.0"
kotlin = "2.2.10"
composeBom = "2026.02.01"
room = "2.8.4"
ksp = "2.3.4"
hilt = "2.57.2"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }

# Room
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "room"}
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "room"}

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

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

# Room
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp"}

# Hilt
hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt"}
3
May 10 at 4:43 PM
User AvatarBenedikt Schlüter
#android#kotlin#dagger-hilt

Accepted Answer

The Hilt version you use is simply too old.

With AGP 9, some things need to be done differently now. Specifically the way the Hilt plugin hooks into the compilation process has changed, and the first version working with AGP 9 is 2.59.

Just update to the newest version (at the time of writing) by changing this in your version catalog:

hilt = "2.59.2"

You can now use alias(libs.plugins.hilt) again in your gradle file. After a Gradle sync your app should be able to be built again.


Looking at your build files, I want to highlight another change with AGP 9: Kotlin comes now buit-in. You do not need to specify the Kotlin plugin org.jetbrains.kotlin.android anymore. To be more precise, it is incompatible now and cannot be used anymore. You already commented it out in your app level gradle file, but you should also remove alias(libs.plugins.kotlin.android) apply false from your project level gradle file and also remove the entry in the version catalog. Delete this line:

kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

The Kotlin version itself (kotlin = "2.2.10") is still needed for the Compose plugin. This superseeds what AGP 9 would otherwise fall back to. By default that is (also) 2.2.10. But you can always use a newer version. The newest one at the time of writing is this:

kotlin = "2.3.21"
User Avatartyg
May 10 at 6:05 PM
3