【问题标题】:Kotlin Scope functions not working in Android studioKotlin Scope 函数在 Android Studio 中不起作用
【发布时间】:2021-12-29 05:46:41
【问题描述】:

无法在 android studio 中使用 kotlin 范围函数,显示未解析的引用。 工作室版本:北极狐2020.3.1补丁4

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
}
def HILT_VERSION ="2.38.1"
def NAV_VERSION = "2.3.5"
def RETROFIT_VERSION = "2.9.0"
def OKHTTP_VERSION = "4.9.0"

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.ezcart"
        minSdk 21
        targetSdk 31
        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'
    }
    dataBinding {
        enabled true
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation "com.google.dagger:hilt-android:$HILT_VERSION"
    kapt "com.google.dagger:hilt-android-compiler:$HILT_VERSION"
    implementation "androidx.navigation:navigation-fragment-ktx:$NAV_VERSION"
    implementation "androidx.navigation:navigation-ui-ktx:$NAV_VERSION"

    implementation "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION"
    // Retrofit with Gson Converter
    implementation "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION"
    implementation 'com.google.code.gson:gson:2.8.9'

    implementation "com.squareup.okhttp3:okhttp:$OKHTTP_VERSION"
    implementation "com.squareup.okhttp3:logging-interceptor:$OKHTTP_VERSION"

    //Glide
    implementation 'com.github.bumptech.glide:glide:4.12.0'

    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

【问题讨论】:

标签: android kotlin


【解决方案1】:

要使用 Kotlin 函数,包括 Scope 函数,请添加依赖项:

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

我是 Kotlin Standard Library,它为使用 Kotlin 的日常工作提供生活必需品。其中包括:

  • 实现惯用模式(让、应用、使用、同步等)的高阶函数。
  • 为集合(eager)和序列(lazy)提供查询操作的扩展函数。
  • 用于处理字符串和字符序列的各种实用程序。
  • JDK 类的扩展,可以方便地处理文件、IO 和线程。

【讨论】:

  • 我已经添加了,您可以在问题本身中看到它
  • 您添加了kotlin-stdlib-jdk7,但kotlin-stdlib 是必需的。请检查。
  • 我没有添加这个.. 项目和应用程序 gradle 文件中使用的版本不匹配。更改以解决问题。
猜你喜欢
  • 1970-01-01
  • 2014-05-14
  • 1970-01-01
  • 2018-12-27
  • 2023-03-15
  • 2017-07-27
  • 2019-08-02
  • 2023-02-06
  • 2016-02-26
相关资源
最近更新 更多