3

After updating my Android Studio Canary version to 3.1, I started receiving Kotlin unresolved references for functions belonging to the kotlin standard library, and the issue also seems to be affecting Android Studio's ability to import the correct library.

I believe my issue is similar to this. Per a recent comment, changing my gradle kotlin version to 1.5.0 fixed the "unresolved reference" issue, but compose beta06 does not support 1.5.0 yet.

I was wondering if anybody had any luck solving this. I believe I have tried to update as many of my dependencies as well as clean building, invalidating cache and restarting.

Here is my gradle file.

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.leetcards"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
        useIR = true
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_version
        kotlinCompilerVersion '1.4.32'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'

dependencies {
    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.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling:$compose_version"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.3.0-alpha07'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"

   // Navigation
    def nav_version = "1.0.0-alpha10"
    implementation "androidx.navigation:navigation-compose:$nav_version"

    // Accompanist
    def accompanist_version = "0.9.0"
    // implementation "com.google.accompanist:accompanist-coil:$accompanist_version"

    // Networking (Retrofit and Moshi)
    def retrofit_version = "2.9.0"
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"

    def moshi_kotlin_version = "1.12.0"
    def moshi_converter_version = "2.9.0"
    implementation "com.squareup.moshi:moshi-kotlin:$moshi_kotlin_version"
    implementation "com.squareup.retrofit2:converter-moshi:$moshi_converter_version"

    // Firebase
    implementation platform('com.google.firebase:firebase-bom:27.1.0')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.firebaseui:firebase-ui-auth:7.1.1'
    implementation 'com.facebook.android:facebook-android-sdk:4.x'
    // Facebook login
    implementation 'com.facebook.android:facebook-android-sdk:[5,6)'

    // CameraX core library using the camera2 implementation
    def camerax_version = "1.0.0"
    // The following line is optional, as the core library is included indirectly by camera-camera2
    implementation "androidx.camera:camera-core:${camerax_version}"
    implementation "androidx.camera:camera-camera2:${camerax_version}"
    // If you want to additionally use the CameraX Lifecycle library
    implementation "androidx.camera:camera-lifecycle:${camerax_version}"
    // If you want to additionally use the CameraX View class
    implementation "androidx.camera:camera-view:1.0.0-alpha24"
}

Justin Yue
  • 41
  • 1
  • 3
  • have the same issue with Epoxy generated model classes, the project is possible to compile, but Studio (2020 Arctic Fox, same in 2021 Bumblebee) still shows Unresolved reference. Change kotlin version, gradle build tools, clean chaches, reinstall AS didn't help. – mtrakal Aug 05 '21 at 07:47

1 Answers1

3

I too have the same problem with Compose project in Android Studio after upgrade to Kotlin 1.5.0. Unresolved references seem to come from the mismatch between Kotlin version defined in project gradle files and Kotlin version bundled with Kotlin plugin. There is some old thread on SO describing similar issue in IntelliJ: link

Summarizing, there are 2 conflicting situations:

  1. Switching to Kotlin 1.5.0 throws error about Jetpack Compose incompatibility;
  2. Downgrading to Kotlin 1.4.32 allows to compile and install the app, however problem with unresolved references arises. Kotlin plugin cannot be easily downgraded (or can it?).

As a temporary measure I am switching between two Kotlin versions, in hope of finding better solution.

Manveru
  • 1,056
  • 8
  • 7