繁体   English   中英

如何解决此错误:数据绑定注释处理器版本需要匹配 Android Gradle 插件版本

[英]How can I solve this error : Data Binding annotation processor version needs to match the Android Gradle Plugin version

我正在尝试对我的项目进行数据绑定,但在我的 Gradle 文件中出现此错误我是初学者,所以让我知道您需要哪些文件或您还需要哪些其他信息?

数据绑定注释处理器版本需要匹配 Android Gradle 插件版本。 您可以删除 kapt 依赖项 androidx.databinding:databinding-compiler:7.1.0-alpha01 和 Android Gradle 插件将注入正确的版本。

build.gradle (:app)

plugins {
    id 'com.android.application'
    id 'kotlin-android'
//    id 'kotlin-android-extensions'
    id 'kotlin-kapt'
    id 'kotlin-parcelize'
//    id "androidx.navigation.safeargs.kotlin"
    id 'androidx.navigation.safeargs.kotlin'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

defaultConfig {
    applicationId "com.example.todoappstevdzaskillshare1"
    minSdkVersion 26
    targetSdkVersion 30
    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 "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

//DataBinding
kapt 'androidx.databinding:databinding-compiler:7.1.0-alpha01'

// Navigation Component
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'

// Room components
implementation "androidx.room:room-runtime:2.3.0"
kapt "androidx.room:room-compiler:2.3.0"
implementation "androidx.room:room-ktx:2.3.0"
androidTestImplementation "androidx.room:room-testing:2.3.0"

// Lifecycle components
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-common-java8:2.3.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"

}

注意:让我知道您还需要哪些文件,我将编辑问题。

需要删除这行代码kapt'androidx.databinding:databinding-compiler:7.1.0-alpha01'重新编译。 根据谷歌的开放数据绑定文档,开放数据绑定的方式是:

android {
        ...
        dataBinding {
            enabled = true
        }
    }

我认为您的 gradle 中已经启用了数据绑定。 因此,只需删除依赖项,就不会发生此错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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