[英]How to Fix error buildFeatures { viewBinding = true } that dont occur in viewBinding { enabled true }
I have just started using android development and trying to use Room library.我刚刚开始使用 android 开发并尝试使用 Room 库。 Since yesterday I am facing this warning message that occurs when I import databinding on my MainActivity.kt
从昨天开始,当我在 MainActivity.kt 上导入数据绑定时,我遇到了这个警告消息
unresolved reference: databinding
未解决的参考:数据绑定
It just runs fine when I input the ActivityMainBinding
class当我输入
ActivityMainBinding
class 时,它运行良好
I was using android Gradle plugin version 4.1.2, so at the first I use buildFeatures { viewBinding = true }
to migrate from kotlin synthetics and then when I try to import databinding to my MainActivity.kt the unresolved problem occur我使用的是 android Gradle 插件版本 4.1.2,所以一开始我使用
buildFeatures { viewBinding = true }
从 kotlin 迁移到我的合成活动,然后尝试导入数据绑定问题。
so I try to use the older version of Binding viewBinding { enabled true }
and it fix this issue所以我尝试使用旧版本的 Binding
viewBinding { enabled true }
并解决了这个问题
The problem is the older version of viewbinding will no longer support to android studio version 5问题是老版本的viewbinding将不再支持android studio version 5
I want to know how to fix this issue, any clue?我想知道如何解决这个问题,有什么线索吗?
Project Build Gradle Porject Build Gradle Picture项目构建 Gradle 项目构建Gradle 图片
MainActivity.kt MainACtivity Picture MainActivity.kt MainActivity图片
App Build Gradle应用程序构建 Gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
} }
android { compileSdkVersion 30 buildToolsVersion "30.0.3" android { compileSdkVersion 30 buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.testingapp.login_mysql"
minSdkVersion 22
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
dataBinding {
enabled = true
}
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'
}
} }
dependencies {依赖{
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
} }
Update更新
when I use the older version of viewbinding, indeed it fixes the issue above But, when I try to run the Application this error occur当我使用旧版本的视图绑定时,确实可以解决上述问题但是,当我尝试运行应用程序时,会发生此错误
DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'.
DSL 元素 'android.dataBinding.enabled' 已过时,已替换为 'android.buildFeatures.dataBinding'。
add this your build.gradle将此添加到您的 build.gradle
android {
buildFeatures {
dataBinding = true
viewBinding = true
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.