How to set ViewBinding in buildgradle.kts?

Viewed 1371

I could easily set dataBinding in buld.gradle.kts by doing:

dataBinding {
    isEnabled = true
}

But I could not seem to find the equivalent for viewBinding.

3 Answers

You need to be on Android Studio 3.6 and add :

android {
  viewBinding.isEnabled = true
}

Update :

You also need your gradle plugin to be at least on 3.6.0

As viewBinding.isEnabled is going to be deprecated, using buildFeatures would be better.

android {
...
    buildFeatures {
        viewBinding = true
    }
}
android {
  viewBinding {
    isEnabled = true
  }
}

With Android Gradle Plugin 3.6.0 or newer, with Android Studio 3.6.0 or newer, and with Android Build Tools newer than 3.6.0 (classpath("com.android.tools.build:gradle:3.6.0")

Related