Android Studio:Kotlin范围函数尚未解决的参考.但是Project编译 [英] Android studio: Kotlin scope functions Unresolved reference. But Project compiles

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

问题描述

我遇到了一个奇怪的问题,我的项目可以成功编译并运行,但是在我的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

渐变属性

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
}

我尝试过使Invalidate cache/Restart无效,也尝试删除.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.

推荐答案

从2周前开始,我在使用Kotlin的Android Studio上经历了类似的经历. 当我在GitHub上使用旧的Kotlin插件版本1.3.31导入项目时.我迅速将其更改为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范围函数尚未解决的参考.但是Project编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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