问题
I'm using androidx for quite a while and my Android project compiles fine, however recently my Android Studio throws tons of red for all Activity classes
because of
cannot access 'androidx.activity.result.ActivityResultCaller' which is a supertype of ...
I use
AppCompatActivity from androidx.appcompat:appcompat:1.1.0
My build.gradle has:
ext.kotlin_version = '1.3.71'
...
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.google.gms:google-services:4.3.3'
And gradle version
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
My gradle.properties:
android.useAndroidX=true
android.enableJetifier=true
org.gradle.jvmargs=-Xmx4608m
org.gradle.parallel=true
# Use kapt in parallel
kapt.use.worker.api=true
# Kapt compile avoidance
kapt.include.compile.classpath=false
回答1:
This happened because of Gradle when resolving dependency libraries versions upgraded androidx.core:core
to version more than 1.2.0, probably to 1.3.0-beta01 or 1.3.0-rc01
AppCompatActivity
extends FragmentActivity
that extends ComponentActivity
that extends androidx.core.app.ComponentActivity
that implements ActivityResultCaller
introduced in androidx.activity:activity:1.2.0-alpha03
only.
To resolve this issue add this dependency to your module build.gradle
:
dependencies {
implementation "androidx.activity:activity-ktx:1.2.0-alpha03"
}
回答2:
In my case, turns out I had conflicting androidx.activity:activity-ktx
gradle dependencies between my core/base and app module.
In addition to ActivityResultCaller, mine was throwing an issue with ActivityResultRegistryOwner.
For me, removing the dependency from the app module, pushing the core module dependency to androidx.activity:activity-ktx:1.2.0-alpha04
and bumping implementation "androidx.core:core-ktx:1.3.0
> 1.3.1
solved both issues.
I also have an androidx.appcompat:appcompat:1.3.0-alpha01
dependency in core, which I kept, but it seems removing it has no effect.
回答3:
In my case, I needed to remove implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'
while keeping implementation "androidx.core:core-ktx:1.3.1"
来源:https://stackoverflow.com/questions/61381545/cannot-access-androidx-activity-result-activityresultcaller