android - 当我在 Android Studio 的 gradle 中添加 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"
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
}
错误 :
在 com.android.build.gradle.internal.dsl.BaseAppModuleExtension 类型的对象上找不到参数 [build_6zjavhoqnf2k7dfs2qrq542f3$_run_closure1$_closure5@6cd00094] 的方法 buildFeatures()。
为什么会出现这个错误?
我该如何解决这个错误?
解决方案
要在您的应用中使用buildFeatures
,您build.gradle
必须使用android gradle plugin 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
}
}
推荐阅读
- grep - Grep:如何只找到一行文本中提到的第一个价格
- php - 如何在 WAMPServer 中启用或安装 PHP 的 mysql_xdevapi 扩展来安装数据表?
- javascript - 如何解决django中Devtools的问题?
- c# - 实体框架重新插入外键引用值
- python - 使用 Python Opencv 在图像中查找问题文本块
- python - QListWidget 选择正在减慢应用程序?
- log4j2 - 为多个包配置 Log4j2
- java - 如何迭代一个大列表以使其更小以使用 Java 流进行 REST 调用?
- aws-lambda - 带有自定义授权器的 lambda 可以使用控制台进行测试,但不能使用邮递员
- jms - ActiveMQ 5.1.5:individualDeadLetterStrategy 未按预期工作