在构建项目时获取以下警告
DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'.
我正在使用Android Studio金丝雀6
在构建项目时获取以下警告
DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'.
我正在使用Android Studio金丝雀6
当前回答
以下工作:
android { compileSdkVersion 30 buildToolsVersion“30.0.3”
defaultConfig {
applicationId "com.poet.navviewmodeljave"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
//dataBinding.enabled true
buildFeatures.dataBinding
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
其他回答
把这段代码放在Gradle Scripts >> build中。gradle(模块:appName.app)
在buildTypes之后,包括数据投标代码
buildTypes {
release {
.......
........
}
}
//here is the code...
buildFeatures {
dataBinding = true
}
这就是全部:)
把它放到构建中。gradle(应用程序级别)。它将适用于大于或等于4.0.0的android studio版本。
android {
buildFeatures{
dataBinding true // for data binding
viewBinding true // for view binding
}
}
如果您正在寻找新的特性viewBinding,可以试试Groovy的这个特性
android {
...
buildFeatures {
viewBinding true
}
}
这是给Kotlin的
android {
...
buildFeatures {
viewBinding true
}
}
但是,要使用默认的android数据绑定
android {
...
buildFeatures {
dataBinding true
}
}
另外,要注意使用
kapt "com.android.databinding:compiler:4.0.0"
出现此警告是因为
dataBinding {
enabled=true
}
viewBinding {
enabled=true
}
这种代码风格已弃用,并将从gradle版本5中删除 现在如果你仍然想使用这个,那么你可以使用androidx遗留的支持依赖项
在应用程序级别build.gradle
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
否则,您可以使用新的代码样式来启用数据绑定和视图绑定
像这样
android {
buildFeatures {
dataBinding = true
// for view binding:
// viewBinding = true
}
}
你必须在gradle模块中添加buildFeatures
android {
buildFeatures{
dataBinding true
}
}
例子:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.demo"
minSdkVersion 21
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
}
buildFeatures{
dataBinding true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'org.jetbrains:annotations:15.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}