18.4 Enabling View Binding
As of Android Studio 4.0, view binding is not enabled by default. To use view binding, therefore, some changes must be made to the build.gradle file for each module in which view binding is needed. In the case of the AndroidSample project, this will require changes to the Gradle Scripts -> build.gradle (Module: AndroidSample.app) file. To begin with, the kotlin-kapt plugin must be applied as follows:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
.
.
Next, the viewBinding property must be enabled within the android section of the file:
.
.
android {
buildFeatures {
viewBinding = true
}
.
.
Finally, the data binding compiler library must be added...