'Can't add buildFeatures to my gradle file when trying to implement viewbinding

I'm sure there's a simple solution to this and I have searched but found no clear solution.

I'm trying to implement viewbinding into my Kotlin project (Kotlin / Android beginner here)

Gradle and Android Studio are version 4.1.2

After adding this code to my grade:app file:

buildFeatures {
        viewbinding true
    }

I get this error:

Build file 'E:\Kotlin-Projects\InstaFire\app\build.gradle' line: 6

A problem occurred evaluating project ':app'.
> No signature of method: build_en51v2o3ickbdp3bg8jg2m4hd.android() is applicable for argument types: (build_en51v2o3ickbdp3bg8jg2m4hd$_run_closure1) values: [build_en51v2o3ickbdp3bg8jg2m4hd$_run_closure1@7a31f1d2]

Here is what my full gradle file looks like:

    plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"


    defaultConfig {
        applicationId "com.neontetra.instafire"
        minSdkVersion 21
        targetSdkVersion 30
        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'
    }

    buildFeatures {
        viewbinding true
    }

}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}


Solution 1:[1]

Looks like I just had to add buildFeatures before all the other code under Android. Silly mistake

Solution 2:[2]

I got Same error.

You need to replace your buildFeatures with bellow tag

viewBinding { enabled true }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Roman Alaivi
Solution 2 Sumit Patel