简体   繁体   English

尝试使用视图绑定时出现 groovy.lang.MissingMethodException

[英]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:我正在做一个大项目,我正在尝试使用两种不同的方法添加视图绑定:

First aproach:第一种方法:

buildFeatures {
    viewBinding true
}

Second aproach:第二种方法:

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.

相关问题 Android Gradle 问题:原因:groovy.lang.MissingMethodException:没有方法签名 - Android Gradle Issue: Caused by: groovy.lang.MissingMethodException: No signature of method 构建 android 项目时出现 intellij idea 错误 - groovy.lang.MissingMethodException:没有方法签名: - intellij idea error while building android project - groovy.lang.MissingMethodException: No signature of method: Android Gradle 构建错误:由以下原因引起:groovy.lang.MissingMethodException:没有方法签名 - Android Gradle build error: Caused by: groovy.lang.MissingMethodException: No signature of method 如何在 ViewBinding 中使用片段? - How to use fragment with ViewBinding? 尝试在Android应用中使用Madrill时出现java.lang.NoSuchMethodError - java.lang.NoSuchMethodError when trying to use Madrill in Android app 尝试使用Mediaplayer时为什么会出现java.lang.ClassNotFoundException? - Why java.lang.ClassNotFoundException when trying to use mediaplayer? 如何在菜单项中使用视图绑定 - How to use viewbinding in menu items 如何在 kotlin 1.4 中使用视图绑定 - How to use viewbinding in kotlin 1.4 为什么使用 ViewBinding 而不是 DataBinding? - Why use ViewBinding over DataBinding? 如何在带有 ItemViewType 的适配器中使用 ViewBinding - How to use ViewBinding in Adapter with ItemViewType
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM