Pradeep
Pradeep

Reputation: 19

When I add viewBinding in gradle in Android Studio, it comes an error

I am using Android Studio version 4.0.1.

When I add viewBinding, it comes an error .

Error when I add viewBinding in gradle.

buildFeatures {
    viewBinding = true
}

build.gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 5
        versionName "1.2.0"
        resValue("string", "growingio_project_id", "8979dc98cc52320f")
        resValue("string", "growingio_url_scheme", "growing.1f3e3791e1d6aee5")
    }
    compileOptions {
        sourceCompatibility rootProject.ext.sourceCompatibilityVersion
        targetCompatibility rootProject.ext.targetCompatibilityVersion
    }

    buildFeatures {
        viewBinding = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: "*.jar")
    implementation deps.swipeRevealLayout
    implementation deps.glide
    implementation deps.growingio
    implementation(deps.rxbus) {
        exclude group: 'com.jakewharton.timber', module: 'timber'
    }
    implementation deps.androidasync
    implementation deps.timber
}

Error :

Could not find method buildFeatures() for arguments [build_6zjavhoqnf2k7dfs2qrq542f3$_run_closure1$_closure5@6cd00094] on object of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.

Why this error comes?

How can I solve this error?

Upvotes: 2

Views: 4177

Answers (3)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363627

To use buildFeatures in your build.gradle you have to use the android gradle plugin 4.0.x

buildscript {
    //..
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.0"
        //....
    }
}

Then you can use:

android {
    //...
    buildFeatures {
        viewBinding true
    }
}

If you are using the android gradle plugin 3.6 you can use:

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

}

Upvotes: 6

Evans Chepsiror
Evans Chepsiror

Reputation: 396

According to the documentation to enable view binding

    buildFeatures {
        viewBinding true
    }

Therefor, get rid of the "=".

Upvotes: 1

wasim mullick
wasim mullick

Reputation: 1

try to add "dataBinding = true" and sync the project

buildFeatures{
        dataBinding = true
        viewBinding = true
    }

Upvotes: 0

Related Questions