Android Studio Canary 2020.3.1: Kotlin未解决的引用问题

3

更新我的Android Studio Canary版本到3.1之后,我开始收到有关属于Kotlin标准库函数的未解决引用,并且该问题似乎也影响了Android Studio导入正确库的能力。

我认为我的问题类似于这个。根据最近的评论,将我的gradle kotlin版本更改为1.5.0修复了“未解决的引用”问题,但Compose beta06尚不支持1.5.0。

我想知道是否有人成功解决了这个问题。我相信我已尝试更新了我的许多依赖项以及清除构建、无效缓存和重启等操作。

这是我的gradle文件。

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


我遇到了与Epoxy生成的模型类相同的问题,项目可以编译,但是Studio(2020 Arctic Fox和2021 Bumblebee)仍然显示未解决的引用。更改Kotlin版本、Gradle构建工具、清除缓存、重新安装AS都没有帮助。 - mtrakal
1个回答

3
在升级到Kotlin 1.5.0后,我也遇到了在Android Studio Compose项目中的同样问题。未解决的引用似乎源于项目Gradle文件中定义的Kotlin版本与Kotlin插件捆绑版本之间的不匹配。在IntelliJ上有一些旧的SO线程描述了类似的问题:链接
总结来说,有两种相互冲突的情况:
  1. 切换到Kotlin 1.5.0会出现Jetpack Compose不兼容的错误;
  2. 降级到Kotlin 1.4.32可以编译和安装应用程序,但是会出现未解决的引用问题。Kotlin插件不能轻松降级(或者可以吗?)。
作为临时措施,我正在两个Kotlin版本之间切换,希望能找到更好的解决方案。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接