如何解决"Cannot access androidx.activity.contextaware.ContextAware'"?
How to solve "Cannot access androidx.activity.contextaware.ContextAware'"?
我正在使用 LiveData 和视图模型构建一个简单的应用程序,但我在 activity 中收到以下警告消息,其中 activity 一些警告
无法访问 'androidx.activity.contextaware.ContextAware',它是 'com.example.movies.presentation.home.MoviesActivity' 的超类型。检查您的模块类路径是否存在缺失或冲突的依赖项
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"
}
当我将 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"
我通过将 appCompat
库升级到从 1.2.0
到 1.3.0-rc01
的最新版本摆脱了这个错误消息。
我正在使用 LiveData 和视图模型构建一个简单的应用程序,但我在 activity 中收到以下警告消息,其中 activity 一些警告
无法访问 'androidx.activity.contextaware.ContextAware',它是 'com.example.movies.presentation.home.MoviesActivity' 的超类型。检查您的模块类路径是否存在缺失或冲突的依赖项
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"
}
当我将 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"
我通过将 appCompat
库升级到从 1.2.0
到 1.3.0-rc01
的最新版本摆脱了这个错误消息。