android. databind .enabled'android. buildfeatures . databinding&# 39;

在构建项目时获取以下警告

DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'.

我正在使用Android Studio Canary 6

91607 次浏览

Android Gradle Plugin 4.0.0-alpha05开始,有一个名为buildFeatures的新块来启用构建功能。

因此,为了使数据绑定与新的AGP插件,你必须在模块(例如:app)级别的gradle文件

构建。gradle (Groovy DSL)

// shorter version
// android.buildFeatures.dataBinding true




// longer version


android {


buildFeatures {


dataBinding true


// for view binding:
// viewBinding true
}
}

kts (Kotlin DSL)

// shorter version
// android.buildFeatures.dataBinding = true




// longer version


android {


buildFeatures {


dataBinding = true


// for view binding:
// viewBinding = true
}
}

参考:https://developer.android.com/studio/releases/gradle-plugin#buildFeatures

把它放到构建中。gradle(应用程序级别)。它将适用于大于或等于4.0.0的android studio版本。

android {
buildFeatures{
dataBinding true // for data binding
viewBinding true // for view binding
}
}

将此代码放在Gradle脚本>>构建。gradle(模块:appName.app)

buildTypes之后,包含数据投标代码

buildTypes {
release {
.......
........
}
}
//here is the code...
buildFeatures {
dataBinding = true
}

这就是全部:)

出现此警告是因为


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
}
}

1-在build下面添加dataBinding功能:

android {
...
buildFeatures {
dataBinding true
}
...
}

2-将匕首版本改为2.31.2

annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
implementation "com.google.dagger:dagger:$daggerVersion"

3- butterKnife版本也更改为10.2.3

implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'

如果你正在寻找新特性viewBinding,试试Groovy

android {
...
buildFeatures {
viewBinding true
}
}

和这个Kotlin

android {
...
buildFeatures {
viewBinding true
}
}

但是,要使用默认的android数据绑定

android {
...
buildFeatures {
dataBinding true
}
}

另外,要注意使用

kapt "com.android.databinding:compiler:4.0.0"

以下工作:

< p > android { compileSdkVersion 30 buildToolsVersion“30.0.3" < / p >
defaultConfig {
applicationId "com.poet.navviewmodeljave"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
//dataBinding.enabled true
buildFeatures.dataBinding
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildFeatures {


//just for dataBinding ,It has nothing to do with viewBinding
dataBinding = true


//just for viewBinding ,It has nothing to do with dataBinding
viewBinding = true
}

看看上面的注释,应该很清楚了