Search code examples
androidgradlegroovyandroid-viewbinding

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]

I am putting this inside android { } on my module:app.

Any idea why this might be happening?


Solution

  • You need to increase android gradle plugin version to 3.6.0 (or higher):

    // Android Gradle Plugin 3.6.0
    android {
        viewBinding {
            enabled = true
        }
    }
    

    Or:

    // Android Gradle Plugin 4.0
    android {
        buildFeatures {
            viewBinding = true
        }
    }