当我在Android Studio的gradle中添加viewBinding时,出现了一个错误
我使用的是Android Studio 4.0.1版 当我添加viewBinding时,出现了一个错误 在gradle中添加viewBinding时出错当我在Android Studio的gradle中添加viewBinding时,出现了一个错误,android,android-gradle-plugin,android-viewbinding,Android,Android Gradle Plugin,Android Viewbinding,我使用的是Android Studio 4.0.1版 当我添加viewBinding时,出现了一个错误 在gradle中添加viewBinding时出错 buildFeatures { viewBinding = true } build.gradle文件 apply plugin: 'com.android.application' android { compileSdkVersion 28 buildToolsVersion "28.0.3"
buildFeatures {
viewBinding = true
}
build.gradle文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 5
versionName "1.2.0"
resValue("string", "growingio_project_id", "8979dc98cc52320f")
resValue("string", "growingio_url_scheme", "growing.1f3e3791e1d6aee5")
}
compileOptions {
sourceCompatibility rootProject.ext.sourceCompatibilityVersion
targetCompatibility rootProject.ext.targetCompatibilityVersion
}
buildFeatures {
viewBinding = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: "*.jar")
implementation deps.swipeRevealLayout
implementation deps.glide
implementation deps.growingio
implementation(deps.rxbus) {
exclude group: 'com.jakewharton.timber', module: 'timber'
}
implementation deps.androidasync
implementation deps.timber
}
错误:
找不到参数[build\u 6zjavhoqnf2k7dfs2qrq542f3$\u run\u closure1]的方法buildFeatures()$_closure5@6cd00094]在
类型的对象
com.android.build.gradle.internal.dsl.BaseAppModuleExtension
为什么会出现这种错误
如何解决此错误?尝试添加“dataBinding=true”并同步项目
buildFeatures{
dataBinding = true
viewBinding = true
}
根据要启用视图绑定的
buildFeatures {
viewBinding true
}
因此,要在
build.gradle中使用buildFeatures
,就要去掉“=”,你必须使用android gradle插件4.0.x
buildscript {
//..
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
//....
}
}
然后您可以使用:
android {
//...
buildFeatures {
viewBinding true
}
}
android{
//....
viewBinding {
enabled = true
}
}
如果您正在使用android gradle插件3.6,您可以使用:
android {
//...
buildFeatures {
viewBinding true
}
}
android{
//....
viewBinding {
enabled = true
}
}
显示您的项目级build.gradle