简体   繁体   中英

Unresolved reference: binding - Kotlin Android

I keep getting the error " Unresolved reference: binding". Does anyone know what I am missing? I already tried updating everything. But the binding won't work.

Build.Gradle.(module.app):

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

android {
    compileSdkVersion 29



    defaultConfig {
        applicationId "com.example.madlevel1example"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildFeatures {
        viewBinding = true}

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

}

I suggest you use dataBinding rather than viewBinding. Altho viewBinding has a shorter build tim. The things Databinding make up for a lot of it.

Refer to this stack link

https://stackoverflow.com/questions/58040778/android-difference-between-databinding-and-viewbinding#:~:text=1%20Answer&text=The%20main%20advantages%20of%20viewbinding,processors%20affecting%20databinding's%20build%20time .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM