gpt4 book ai didi

android - 错误 : cannot find symbol | class ApplicationComponent

转载 作者:行者123 更新时间:2023-12-04 14:37:01 24 4
gpt4 key购买 nike

我正在尝试在我的项目中使用 Hilt 注入(inject)。我将依赖项添加到我的 build.gradle 文件中,然后创建了基础应用程序类,该类继承自 Applcication(),并使用 @HiltAndroidApp 对其进行了注释。这样做之后,我继续为 Hilt 重建项目以生成文件,但它给了我这个错误。

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
我的 build.gradle 文件:
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"
我的 build.gradle(项目名称)
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
}
我的 baseApplication 类:
package com.example.testing

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class BaseApplication: Application() {
}

最佳答案

替换 ApplicationComponentSingletonComponent .
(解释:
另见error: cannot find symbol @dagger.hilt.InstallIn(value = {ApplicationComponent.class}) .
我得到了这个构建错误:

@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已在 Dagger Hilt 中删除诉 2.31.)

关于android - 错误 : cannot find symbol | class ApplicationComponent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66174469/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com