将 Android Studio 更新到 2020.3.1 Canary 14 Build 后未解决的 Kotlin 引用

时间:2021-04-12 17:48:09

标签: android kotlin

我目前遇到 Android Studio 警告我某些不存在的 Kotlin 函数。我认为这是 Android Studio 唯一的问题,因为我可以很好地编译和运行我的项目

例如,Android Studio 无法识别 val rows = mutableListOf<MeasuredRow>()。它提供警告:Unresolved reference: mutableListOf。也就是说,我可以很好地使用其他一些 Kotlin 函数和类。

唯一的解决方案是降级,这是我不想想做的

应用范围的gradle:

buildscript {
    ext.kotlin_version = "1.4.32"
    ext.compose_version = '1.0.0-beta04'
    ext.hilt_version = '2.33-beta'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0-alpha14'
        classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }

    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
        kotlinOptions {
            jvmTarget = '1.8'
            allWarningsAsErrors = false
            // Opt-in to experimental compose APIs
            freeCompilerArgs += '-Xopt-in=kotlin.RequiresOptIn'
            // Enable experimental coroutines APIs, including collectAsState()
            freeCompilerArgs += '-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

特定于应用模块的 Gradle:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.test"
        minSdkVersion 23
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
    }
    buildscript {
        apply from: '../dependencies.gradle'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.0.0-beta04'
    }
    buildTypes {
        release {
            minifyEnabled true
            debuggable false
            shrinkResources = true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    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.compiler:compiler:1.0.0-beta04"
    implementation 'androidx.compose.ui:ui:1.0.0-beta04'
    implementation 'androidx.compose.ui:ui-tooling:1.0.0-beta04'
    implementation 'androidx.compose.foundation:foundation:1.0.0-beta04'
    implementation 'androidx.compose.material:material:1.0.0-beta04'
    implementation 'androidx.activity:activity-compose:1.3.0-alpha06'
    implementation 'androidx.compose.runtime:runtime-livedata:1.0.0-beta04'
    implementation "androidx.navigation:navigation-compose:1.0.0-alpha09"
    implementation "androidx.hilt:hilt-navigation-compose:1.0.0-alpha01"
    implementation 'dev.chrisbanes.accompanist:accompanist-insets:0.6.2'

    // ViewModel
    def lifecycle_version = "2.3.1"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha04'
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"

    // hilt
    implementation "com.google.dagger:hilt-android:$hilt_version"
    kapt "com.google.dagger:hilt-compiler:$hilt_version"

    // Image Loading
    implementation group: 'com.google.accompanist', name: 'accompanist-imageloading-core', version: '0.7.0'
    implementation "com.google.accompanist:accompanist-glide:0.7.0"
}

重要的是要知道我的应用可以正常运行并且可以毫无问题地安装(即使是全新安装)

我尝试过的:

  • 重新安装 Windows PC
  • 使缓存无效/重新启动
  • 删除主目录中的 .Android studio
  • 删除 ./.idea 文件夹

1 个答案:

答案 0 :(得分:-1)

它现在对我有用。

AS 2020.3.1 金丝雀 15

科特林 1.5.0