Android Studio 通过viewModels()未解析的引用

elcex8rz  于 2022-11-16  发布在  Android
关注(0)|答案(1)|浏览(213)

我遇到了一个问题,Android Studio将by viewModels()突出显示为错误,但代码已成功编译并正常工作。此问题仅在Activity中出现,而在Fragment中没有此类错误。如果我使用by viewModel()(Koin)而不是by viewModels(),也会出现同样的问题。我查看了很多决策,但没有一个对我有帮助。
我试探着:

  • 使缓存无效
  • 重新启动IDE、PC...
  • 在另一台电脑上打开项目
  • 已尝试this答案和this

Error
我的依赖项(应用程序):

implementation(project(":domain"))
implementation(project(":data"))

implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'

def koin_version= "3.2.1"
implementation "io.insert-koin:koin-android:$koin_version"

implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.8.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation "androidx.fragment:fragment-ktx:1.5.3"
implementation 'com.my.target:mytarget-sdk:5.15.4'

def lottieVersion = "5.2.0"
implementation "com.airbnb.android:lottie:$lottieVersion"

implementation 'com.google.firebase:firebase-crashlytics-ktx:18.2.13'
implementation 'com.google.firebase:firebase-config-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation platform('com.google.firebase:firebase-bom:30.3.1')
implementation 'com.google.android.gms:play-services-auth:20.3.0'
implementation 'com.google.android.gms:play-services-oss-licenses:17.0.0'
implementation 'com.google.android.gms:play-services-location:20.0.0'

implementation 'com.github.bumptech.glide:glide:4.13.2'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'

建(项目)级:

buildscript {
    repositories {
        google()
    }
    dependencies {
        classpath 'com.google.android.gms:oss-licenses-plugin:0.10.5'
        classpath 'com.google.gms:google-services:4.3.14'
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
    }
}
plugins {
    id 'com.android.application' version '7.3.0' apply false
    id 'com.android.library' version '7.3.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
    id 'org.jetbrains.kotlin.jvm' version '1.7.10' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
vc9ivgsu

vc9ivgsu1#

我也遇到了这个问题。AppCompatActivity是从ComposeActivity派生的,但不知何故,Android Studio没有得到这一点,并将其显示为错误。

相关问题