简体   繁体   English

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

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

I am trying to data bind my project but I am getting this error in my Gradle file I am a beginner so let me know which files you need or what other information do you need more?我正在尝试对我的项目进行数据绑定,但在我的 Gradle 文件中出现此错误我是初学者,所以让我知道您需要哪些文件或您还需要哪些其他信息?

Data Binding annotation processor version needs to match the Android Gradle Plugin version.数据绑定注释处理器版本需要匹配 Android Gradle 插件版本。 You can remove the kapt dependency androidx.databinding:databinding-compiler:7.1.0-alpha01 and Android Gradle Plugin will inject the right version.您可以删除 kapt 依赖项 androidx.databinding:databinding-compiler:7.1.0-alpha01 和 Android Gradle 插件将注入正确的版本。

build.gradle (:app) 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"

}

NOTE: Let me know which more files do you need and I will edit the question.注意:让我知道您还需要哪些文件,我将编辑问题。

You need to delete this line of code kapt'androidx.databinding:databinding-compiler:7.1.0-alpha01' and recompile.需要删除这行代码kapt'androidx.databinding:databinding-compiler:7.1.0-alpha01'重新编译。 According to Google's open databinding document, the way to open databinding is:根据谷歌的开放数据绑定文档,开放数据绑定的方式是:

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

I think databinding is already enabled in your gradle.我认为您的 gradle 中已经启用了数据绑定。 So just delete the dependency and this error shouldn't occur.因此,只需删除依赖项,就不会发生此错误。

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

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