I am trying to work with Hilt injection in my project. I added the dependecies into my build.gradle file and then i created the the base application class, this class inherits from Applcication() and i annotated it with @HiltAndroidApp. After doing this i went ahead and rebuild the project for Hilt to generate the files but it give me this error.
D:\AndroidStudioProjects\testing\app\build\generated\source\kapt\debug\com\example\testing\BaseApplication_GeneratedInjector.java:4: error: cannot find symbol
import dagger.hilt.android.components.ApplicationComponent;
^
symbol: class ApplicationComponent
location: package dagger.hilt.android.componentsD:\AndroidStudioProjects\testing\app\build\generated\source\kapt\debug\com\example\testing\BaseApplication_GeneratedInjector.java:12: error: cannot find symbol
My build.gradle file:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'dagger.hilt.android.plugin'
id 'kotlin-kapt'
}
...
implementation "com.google.dagger:dagger:2.31"
kapt "com.google.dagger:dagger-compiler:2.28"
// Dagger Android
api 'com.google.dagger:dagger-android:2.28.1'
api 'com.google.dagger:dagger-android-support:2.28.1'
kapt 'com.google.dagger:dagger-android-processor:2.23.2'
implementation "com.google.dagger:hilt-android:2.31-alpha"
kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0-alpha03"
My build.gradle(Porject name)
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.28-alpha"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
My baseApplication class:
package com.example.testing
import android.app.Application
import dagger.hilt.android.HiltAndroidApp
@HiltAndroidApp
class BaseApplication: Application() {
}
Replace ApplicationComponent
with SingletonComponent
.
(Explanation:
see also error: cannot find symbol @dagger.hilt.InstallIn(value = {ApplicationComponent.class}).
I got this build error:
@dagger.hilt.InstallIn(value = {ApplicationComponent.class})
^
symbol: class ApplicationComponenterror: [Hilt]
@InstallIn, 'value' class is invalid or missing: @dagger.hilt.InstallIn({<error>})
[Hilt] Processing did not complete. See error above for details.
ApplicationComponent
was removed in Dagger Hilt
v. 2.31.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With