[英]android studio when I try add dependency into the project Gradle file I get this error
[英]When I add viewBinding in gradle in Android Studio, it comes an error
我正在使用 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"
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
}
错误:
Could not find method buildFeatures() for arguments [build_6zjavhoqnf2k7dfs2qrq542f3$_run_closure1$_closure5@6cd00094] on object of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.
为什么会出现这个错误?
我该如何解决这个错误?
要在build.gradle
中使用buildFeatures
,您必须使用android gradle 插件 4.0.x
buildscript {
//..
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
//....
}
}
然后你可以使用:
android {
//...
buildFeatures {
viewBinding true
}
}
如果您使用的是android gradle 插件 3.6 ,您可以使用:
android{
//....
viewBinding {
enabled = true
}
}
尝试添加“dataBinding = true”并同步项目
buildFeatures{
dataBinding = true
viewBinding = true
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.