How to enable View Binding in Android Studio (Kotlin)
To enable View Binding in Android Studio, you need to open the build.gradle (module) file in the Gradle Scripts section.
You need to add the following code to the android block:
android {
buildFeatures {
viewBinding = true
}
}
Then you can click on the link Sync Now in the top right corner or run the project.
Entire android block example:
android {
namespace 'ru.podelitsa.myapplication'
compileSdk 32
buildFeatures {
viewBinding = true
}
defaultConfig {
applicationId "ru.podelitsa.myapplication"
minSdk 26
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
Comments