16

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
Adam Styrc
  • 1,517
  • 2
  • 23
  • 38

3 Answers3

40

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"
}
Nistix
  • 723
  • 10
  • 7
  • I managed to fix it with some AS update, but then a new AS came, and the problem returned. Thx, this is the correct answer! :) – Adam Styrc Jun 03 '20 at 05:46
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.

Mochamad Taufik Hidayat
  • 1,264
  • 3
  • 21
  • 32
barmacki
  • 31
  • 6
1

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"

Carter Hudson
  • 1,176
  • 1
  • 11
  • 23