[英]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.