Android Studio:Kotlin 作用域函数未解析参考.但项目编译 [英] Android studio: Kotlin scope functions Unresolved reference. But Project compiles

查看:34
本文介绍了Android Studio:Kotlin 作用域函数未解析参考.但项目编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临这个奇怪的问题,我的项目编译并成功运行,但在我的 kotlin 范围函数中出现红色错误.它还显示了一些 kotlin 函数的错误,如 toLong()、toDouble() 等.

I am facing this strange issue where my project compiles and runs successfully but in my kotlin scope functions red errors are coming. It also shows errors on some of the kotlin functions like toLong(), toDouble() etc.

我的gradle文件中有这个

and I have this in my gradle file

   apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.xyz"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 4
        multiDexEnabled true
        versionName "1.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }

    dataBinding {
        enabled = true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    def lifecycle_version = "2.0.0"
    def room_version = "beta01"
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //android X
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"

    implementation 'com.android.support:multidex:1.0.3'

    api 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
    api 'de.hdodenhof:circleimageview:3.0.0'
    api 'com.jakewharton:butterknife:10.1.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'

    // For Kotlin use kapt instead of annotationProcessor
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.20'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'
    implementation "androidx.room:room-runtime:2.2.0-$room_version"
    implementation "androidx.room:room-ktx:2.2.0-$room_version"
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
    api(name: 'sdk-release-1.6.1', ext: 'aar') {
        transitive = true
    }
    // Add the Firebase SDK for Google Analytics
    implementation 'com.google.firebase:firebase-analytics:17.2.0'
    implementation 'com.google.firebase:firebase-messaging:20.0.0'
    //annotation processors
    annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
    annotationProcessor "androidx.room:room-compiler:2.2.0-$room_version"
    // Add dependency
    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
    //facebook app events sdk
    implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
}
apply plugin: 'com.google.gms.google-services'  // Google Play services Gradle plugin

Gradle 属性

org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
android.enableJetifier=true

构建gradle

    buildscript {

    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20"
        classpath 'com.google.gms:google-services:4.3.1'
        classpath 'io.fabric.tools:gradle:1.31.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

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

我尝试过使缓存无效/重新启动并尝试删除 .idea 和 .gradle 文件没有任何帮助,我还尝试重新启动 android studio 并尝试从 git 更改分支没有任何帮助.任何帮助表示赞赏.

I have tried Invalidate cache/Restart and also tried deleting .idea and .gradle files nothing helped, I have also tried to restart the android studio and also tried to change branches from git nothing helped. any help appreciated.

推荐答案

两周前我在 Android Studio 和 Kotlin 上有过类似的体验.当我使用旧的 Kotlin 插件版本 1.3.31 在 GitHub 上导入一个项目时.我赶紧把它改成1.3.72(最新的kotlin),然后我也有这个错误.

I had similar experience on Android Studio with Kotlin since 2 weeks ago. When I import a project on GitHub with old Kotlin plugin version 1.3.31. I quickly changed it to 1.3.72 (the latest kotlin) then, I had had this error too.

当我将插件版本更改为 1.3.61(旧版本)并同步我的项目时,我可以修复错误.它删除了错误并将其更新到最新的插件版本 1.3.72.现在一切都很顺利.

I could fix the error when I changed the plugin version to 1.3.61 (older version) and sync my project. It removed the error and update it to the latest plugin version 1.3.72. And everything worked smoothly now.

buildscript {
    ext.kotlin_version = '1.3.72'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.0-alpha06"
    }
}

我就像魔术一样.

刚刚将 Kotlin 插件版本更改为 2 或 3 个旧版本向后并同步您的项目.我应该工作

Just changed the Kotlin plugin version to a 2 or 3 older versions backward and sync your project. I should work

希望能帮到你

这篇关于Android Studio:Kotlin 作用域函数未解析参考.但项目编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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