21

I am trying to implement ViewBinding on Android Studio as described in the documentation.

But I get following error:

ERROR: Could not find method viewBinding() for arguments [build_86jkemkg0wj9ybuijdbbuahly$_run_closure1$_closure5@2714f9c5] on object of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.

I have the latest version of Android Studio for Linux.

Why I am getting an error?

Muhammed Ozdogan
  • 5,341
  • 8
  • 32
  • 53
  • 1
    To confirm, by "latest version", do you mean Android Studio 3.6 Canary 11 or higher? – CommonsWare Sep 15 '19 at 20:35
  • Help->About says Android Studio 3.5. Also, lastest build at "https://developer.android.com/studio/" is 3.5. Is it a feature that will be implemented at next version? – Muhammed Ozdogan Sep 15 '19 at 20:38

2 Answers2

27

8/3/2020 update
After update to AS 3.6.1 you should update your android gradle version to 3.6.1 > classpath 'com.android.tools.build:gradle:3.6.0'


Orignal solution
Android Studio 3.6 and above, From the Left menu, select Project > Gradle Scripts > gradle-wrapper.properties then modify the distributionUrl and set it to https\://services.gradle.org/distributions/gradle-5.6.4-all.zip after that sync your project with Sync Project with Gradle Files, after it's finished go back to your build.gradle (Project) and update the dependencie of gradle classpath to classpath 'com.android.tools.build:gradle:3.6.0', almost done.
Now it's time to enable it, in your build.gradle(:app) set it

viewBinding {
    enabled = true
}

12/16/2020 update

With classpath 'com.android.tools.build:gradle:4.1.1' viewBinding is deprecated, you have to use:

buildFeatures {
    viewBinding = true
}
Artificioo
  • 704
  • 1
  • 9
  • 19
Amjad Alwareh
  • 2,926
  • 22
  • 27
18

Help->About says Android Studio 3.5

View binding is a part of Android Studio 3.6. Right now, that is in a preview ("canary") release version.

Is it a feature that will be implemented at next version?

Correct. If you wish, you can install the preview version of Android Studio 3.6 alongside your Android Studio 3.5, to experiment with the feature. Or, you can wait a few months for Android Studio 3.6 to ship a release version, then use view binding at that point.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks, CommonsWare. I think I have to import ButterKnife library for view injection. – Muhammed Ozdogan Sep 15 '19 at 20:45
  • 8
    Converting existing project to work with View binding in AS 3.6 also requires changes to: * `gradle-wrapper.properties` change gradle version to `5.6.1` * `build.gradle. change `com.android.tools.build:gradle` version to `3.6.0-beta04` – Oleksii Masnyi Nov 14 '19 at 20:32