Android Studio Canary 2020.3.1:Kotlin 未解析引用 [英] Android Studio Canary 2020.3.1: Kotlin Unresolved References

查看:112
本文介绍了Android Studio Canary 2020.3.1:Kotlin 未解析引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将我的 Android Studio Canary 版本更新到 3.1 后,我开始收到属于 kotlin 标准库的函数的 Kotlin 未解析引用,这个问题似乎也影响了 Android Studio 导入正确库的能力.

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.

我相信我的问题类似于 这个.根据最近的评论,将我的 gradle kotlin 版本更改为 1.5.0 修复了未解决的引用"问题.问题,但 compose beta06 尚不支持 1.5.0.

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.

这是我的 gradle 文件.

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

推荐答案

我在升级到 Kotlin 1.5.0 后在 Android Studio 中使用 Compose 项目也有同样的问题.未解决的引用似乎来自项目 gradle 文件中定义的 Kotlin 版本与 Kotlin 插件捆绑的 Kotlin 版本之间的不匹配.有一些关于 SO 的旧线程描述了 IntelliJ 中的类似问题:link

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. 切换到 Kotlin 1.5.0 会引发有关 Jetpack Compose 不兼容的错误;
  2. 降级到 Kotlin 1.4.32 允许编译和安装应用程序,但是会出现未解析引用的问题.Kotlin 插件不能轻易降级(或者可以吗?).

作为临时措施,我在两个 Kotlin 版本之间切换,希望找到更好的解决方案.

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

这篇关于Android Studio Canary 2020.3.1:Kotlin 未解析引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆