Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: cannot find symbol | class ApplicationComponent

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() {
}
like image 409
Johan Avatar asked Dec 08 '22 09:12

Johan


1 Answers

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.)

like image 147
CoolMind Avatar answered Dec 25 '22 23:12

CoolMind