[英]groovy.lang.MissingMethodException when trying to use viewbinding
I'm working on a big project and I'm trying to add view binding using two different aproaches:我正在做一个大项目,我正在尝试使用两种不同的方法添加视图绑定:
buildFeatures {
viewBinding true
}
viewBinding {
enabled true
}
On both cases I get a Caused by: groovy.lang.MissingMethodException: No signature of method: build_4xgux05b5phesnrai6p6fg7vc.android() is applicable for argument types: (build_4xgux05b5phesnrai6p6fg7vc$_run_closure3) values: [build_4xgux05b5phesnrai6p6fg7vc$_run_closure3@5e534db6]
On both cases I get a
Caused by: groovy.lang.MissingMethodException: No signature of method: build_4xgux05b5phesnrai6p6fg7vc.android() is applicable for argument types: (build_4xgux05b5phesnrai6p6fg7vc$_run_closure3) values: [build_4xgux05b5phesnrai6p6fg7vc$_run_closure3@5e534db6]
I am putting this inside android { }
on my module:app.我把它放在我的模块:app 上的
android { }
中。
Any idea why this might be happening?知道为什么会发生这种情况吗?
You need to increase android gradle plugin version to 3.6.0 (or higher):您需要将 android gradle 插件版本增加到 3.6.0(或更高):
// Android Gradle Plugin 3.6.0
android {
viewBinding {
enabled = true
}
}
Or:或者:
// Android Gradle Plugin 4.0
android {
buildFeatures {
viewBinding = true
}
}
I was having the same issue on my Android Studio, what I did to fix it was this:我在我的 Android Studio 上遇到了同样的问题,我做了什么来解决它:
Before the之前
android {
...
}
I check the plugins fields, ie:我检查插件字段,即:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt' <- this one is when you need to use databinding I think
}
For my case to fix this issue I just add the line对于我的情况来解决这个问题,我只需添加该行
id 'kotlin-android-extensions'
And all works as expected, hope this answer would be useful for your problem一切都按预期工作,希望这个答案对您的问题有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.