error: [Hilt] Expected @AndroidEntryPoint to have a value
s1nyx opened this issue · 3 comments
Hi,
I am having an issue with Hilt when i try to build my app on Android Studio.
I get this error :
/Users/sinyx/AndroidStudioProjects/MiniProjet/app/build/tmp/kapt3/stubs/debug/com/example/mini_projet/MainActivity.java:10: error: [Hilt] Expected @AndroidEntryPoint to have a value. Did you forget to apply the Gradle Plugin? (com.google.dagger.hilt.android)
public final class MainActivity extends androidx.activity.ComponentActivity {
^
See https://dagger.dev/hilt/gradle-setup.html
[Hilt] Processing did not complete. See error above for details.
I have @AndroidEntryPoint
in my MainActivity.kt
and @HiltAndroidApp
in my ProjectApp.kt
.
So I don't understand what I am doing wrong.
More informations on the app:
Github: https://github.com/s1nyx/supinfo-eng3-3andm-projet
Project build.gradle.kts:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
id("com.google.dagger.hilt.android") version "2.48.1" apply false
}
buildscript {
repositories {
// other repositories...
mavenCentral()
}
dependencies {
classpath("com.google.dagger:hilt-android-gradle-plugin:2.48.1")
}
}
Module build.gradle.kts:
val hilt_version = "2.48.1"
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsKotlinAndroid)
id("com.google.devtools.ksp") version "1.9.21-1.0.15"
kotlin("kapt")
id("com.google.dagger.hilt.android") version "2.48.1" apply false
}
android {
namespace = "com.example.mini_projet"
compileSdk = 34
defaultConfig {
applicationId = "com.example.mini_projet"
minSdk = 26
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}
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"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}
dependencies {
implementation(libs.androidx.lifecycle.viewmodel.compose)
val roomVersion = "2.6.1"
implementation("androidx.room:room-runtime:$roomVersion")
// To use Kotlin annotation processing tool (kapt)
ksp("androidx.room:room-compiler:$roomVersion")
// optional - Kotlin Extensions and Coroutines support for Room
implementation("androidx.room:room-ktx:$roomVersion")
// Injection de dépendances
implementation("com.google.dagger:hilt-android:$hilt_version")
kapt("com.google.dagger:hilt-android-compiler:$hilt_version")
// For instrumentation tests
androidTestImplementation("com.google.dagger:hilt-android-testing:$hilt_version")
kaptAndroidTest("com.google.dagger:hilt-compiler:$hilt_version")
// For local unit tests
testImplementation("com.google.dagger:hilt-android-testing:$hilt_version")
kaptTest("com.google.dagger:hilt-compiler:$hilt_version")
// Ktor for HTTP requests
val ktor_version = "2.3.9"
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("io.ktor:ktor-client-content-negotiation:$ktor_version")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
implementation("io.coil-kt:coil-compose:2.6.0")
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation("androidx.compose.runtime:runtime-livedata:1.6.4")
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
}
// Allow references to generated code
kapt {
correctErrorTypes = true
}
Hi, @s1nyx , I think it's because the Hilt Gradle plugin is not applied. In your module build.gradle.kts you can try replacing this line:
id("com.google.dagger.hilt.android") version "2.48.1" apply false
to this:
id("com.google.dagger.hilt.android")
Hi, @s1nyx , I think it's because the Hilt Gradle plugin is not applied. In your module build.gradle.kts you can try replacing this line:
id("com.google.dagger.hilt.android") version "2.48.1" apply false
to this:
id("com.google.dagger.hilt.android")
Hey, I just done it, after cleaning and rebuild I get this error Caused by: java.lang.IllegalStateException: The KSP plugin was detected to be applied but its task class could not be found.
Okay I found the issue.
In the Module build.gradle.kts :
Renamed id("com.google.devtools.ksp") version "1.9.21-1.0.15"
to id("com.google.devtools.ksp")
In the Project build.gradle.kts:
Added id("com.google.devtools.ksp") version "1.9.21-1.0.15"
Works perfectly now :D Thanks !