安卓工作室Canary 2020.3.1:Kotlin未解决的参考文献



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

我相信我的问题与此类似。根据最近的评论,将我的gradle kotlin版本更改为1.5.0修复了";未解析引用";问题,但composebeta06还不支持1.5.0。

我想知道是否有人能幸运地解决这个问题。我相信我已经尝试过更新尽可能多的依赖项,以及清理构建、使缓存无效和重新启动。

这是我的成绩单档案。

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插件捆绑的Kotln版本之间的不匹配。SO上有一些旧线程在IntelliJ中描述了类似的问题:链接

总之,有两种冲突情况:

  1. 切换到Kotlin 1.5.0会引发关于Jetpack Compose不兼容的错误
  2. 降级到Kotlin 1.4.32允许编译和安装该应用程序,但出现了未解决引用的问题。Kotlin插件不能轻易降级(或者可以吗?(

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

最新更新