9

I have installed Android Studio 3.6 Canary 12 and I want to use viewBinding feature

According to the documentation, I put this code in my build.gradle (app module)

android {
   ...
   viewBinding.enabled = true
   ...
}

But I get this error

A problem occurred evaluating project ':app'.
> Could not get unknown property 'viewBinding' for object of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.

Need help ! Thanks !

Agnaramon
  • 851
  • 10
  • 15
  • 1
    Check your Android Gradle Plugin version in your top-level `build.gradle` file. Make sure you are using the version that matches your Android Studio version. – CommonsWare Sep 21 '19 at 13:07
  • Thanks. It required Android Gradle Plugin 3.6.0-alpha12. After choosing it that's ok ! – Agnaramon Sep 21 '19 at 18:46

4 Answers4

5

As given in Official Website

Put it like:

android {
    ...
    viewBinding {
        enabled = true
    }
}

Please check your Android Studio Version too, It must be 3.6 Canary 11+.

Also check Gradle Plugin - Android Gradle Plugin 3.6.0-alpha12

NOTE: View binding is available in Android Studio 3.6 Canary 11+.

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
5

Thanks for you support !

I've solved it by using Android Gradle Plugin 3.6.0-alpha12

Agnaramon
  • 851
  • 10
  • 15
  • 2
    FWIW, I wrote up [a blog post](https://commonsware.com/blog/2019/09/22/view-binding-android-studio-versions.html) with a bit more about this. – CommonsWare Sep 22 '19 at 14:32
5

Some things have changed a little if you are using Android Gradle plugin >= 4.0.0-alpha05.

viewBinding.enabled = true is now deprecated

You should use the Android buildFeatures block instead:

android {
    buildFeatures {
        // Determines whether to support View Binding.
        // Note that the viewBinding.enabled property is now deprecated.
        viewBinding = true
    }
}

If you want the feature enabled by default in all of your modules you can turn on it in gradle.properties:

android.defaults.buildfeatures.viewBinding=true

Docs: https://developer.android.com/studio/preview/features/#4.0

Gui Silva
  • 1,341
  • 15
  • 18
0

Please check the solution from here. and update your AS to the stable version of AS 3.6

Amjad Alwareh
  • 2,926
  • 22
  • 27