无法导入@Inject 注释

问题描述

我已经在我的项目中实现了 Hilt 依赖项,但是当我的构造函数需要 @Inject 注释时,它不起作用。基本上,当我尝试手动导入它时,我发现,javax 中的注入文件夹是空的。所以结构就像javax.inject。之后我什么也没得到,因为注入文件夹是空的。我试过重建和清理他的项目。我也尝试过使缓存无效,但似乎没有任何效果。我怎样才能做到这一点?

依赖列表

dependencies {
    implementation(project(":shared"))

    implementation(AndroidX.appCompat)

    implementation(Compose.runtime)
    implementation(Compose.runtimeLiveData)
    implementation(Compose.ui)
    implementation(Compose.material)
    implementation(Compose.uiTooling)
    implementation(Compose.foundation)
    implementation(Compose.compiler)
    implementation(Compose.constraintLayout)
    implementation(Compose.activity)
    implementation(Compose.navigation)

    implementation(Google.material)

    implementation(Hilt.hiltAndroid)
    implementation(Hilt.hiltNavigation)
    kapt(Hilt.hiltCompiler)

    implementation(Kotlinx.datetime)

    debugImplementation(SquareUp.leakCanary)
}

刀柄版本 - 2.37

解决方法

我相信您缺少 gradle 文件中的插件

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
}
,

你所有的依赖都是正确的,这只是一个android studio bug!

我在使用 Android Studio 4.2.2 时遇到了同样的问题,我使用 Android Studio 的测试版解决了