Search code examples
androidandroid-studioandroid-activityandroidx

Cannot access 'androidx.activity.result.ActivityResultCaller'


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

enter image description here 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

Solution

  • 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"
    }