android - 如何解决“"Cannot access androidx.activity.contextaware.ContextAware'”?

标签 android android-studio gradle android-livedata android-lifecycle

我正在使用 LiveData 和 viewmodels 构建一个简单的应用程序,但是我在我的 Activity 中收到以下警告消息,这些警告消息覆盖了我的 Activity 一些警告
无法访问“com.example.movi​​es.presentation.home.MoviesActivity”的父类(super class)型“androidx.activity.contextaware.ContextAware”。检查您的模块类路径是否存在缺失或冲突的依赖关系

  dependencies {
    
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    // ViewModel
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$life_cycle_version"

    // LiveData
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$life_cycle_version"

    implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
    kapt "androidx.lifecycle:lifecycle-compiler:$life_cycle_version"

    // Hilt
    implementation "com.google.dagger:hilt-android:$hilt_version"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$life_cycle_version"
    kapt "com.google.dagger:hilt-android-compiler:$hilt_version"

    //moshi
    implementation("com.squareup.moshi:moshi:$moshi_version")
    kapt("com.squareup.moshi:moshi-kotlin-codegen:$moshi_version")

    //retrofit
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"
    implementation("com.squareup.okhttp3:logging-interceptor:$okhttp_version")

    //espresso testing
    androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_core"
    androidTestImplementation "androidx.test:runner:$test_runner"
    androidTestImplementation "androidx.test:rules:$test_runner"

    // Hilt For instrumentation tests
    androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_testing"
    androidTestAnnotationProcessor "com.google.dagger:hilt-compiler:$hilt_testing"

    //Hilt For local unit tests
    testImplementation "com.google.dagger:hilt-android-testing:$hilt_testing"
    testAnnotationProcessor "com.google.dagger:hilt-compiler:$hilt_testing"

    //mockk for testing
    testImplementation "io.mockk:mockk:$mockk_version"

    //coroutine testing
    testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutine_test_version"

    testImplementation("org.junit.jupiter:junit-jupiter-api:$junit_5")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junit_5")

    testImplementation "android.arch.core:core-testing:$arch_version"
我的模块 build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.4.31"
    ext.hilt_version = '2.31.2-alpha'
    ext.junit = '1.7.1.1'


    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
        classpath "de.mannodermaus.gradle.plugins:android-junit5:$junit"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
ext {
    life_cycle_version = "2.2.0"
    espresso_core = "3.3.0"
    test_runner = "1.3.0"
    hilt_testing = "2.33-beta"
    moshi_version = "1.10.0"
    mockk_version = "1.11.0"
    retrofit_version = "2.9.0"
    okhttp_version = "4.9.0"
    coroutine_test_version = "1.4.3"
    junit_5 = "5.7.1"
    arch_version = "2.2.0"
}
enter image description here

最佳答案

当我将 Activity jetpack 模块添加到 gradle 文件时,它已解决

def activity_version = "1.2.2"

// Java language implementation
    implementation "androidx.activity:activity:$activity_version"
    // Kotlin
implementation "androidx.activity:activity-ktx:$activity_version"

关于android - 如何解决“"Cannot access androidx.activity.contextaware.ContextAware'”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66810183/

相关文章:

android - 在安装适用于Windows 7(64位)的Android SDK之后,为什么没有加载任何程序包?

android - onNavigationItemSelected 在 NavigationView 中不起作用

gradle - Android studio 用 Gradle 版本取笑我

android - 停止 ADB 服务器失败(代码 -1)。解压缩失败........(访问被拒绝) - Android Studio

java - 使用 Jetty 和 Gradle 自动重新加载静态内容

android - Galaxy S5 上的 Apache cordova 相机重启应用程序

android - 无法在 Android Studio 中启动模拟器

kotlin - 创建 jvm 和 Kotlin 多平台的 Github 库组合

java - 将 logback classic 与 gradle 结合使用时无法加载 logback 配置

Android 可穿戴设备 - 如何自动安装可穿戴应用程序