Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable viewBinding feature failed (Android Studio 3.6)

I have installed Android Studio 3.6 Canary 12 and I want to use viewBinding feature

According to the documentation, I put this code in my build.gradle (app module)

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

But I get this error

A problem occurred evaluating project ':app'.
> Could not get unknown property 'viewBinding' for object of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.

Need help ! Thanks !

like image 413
Agnaramon Avatar asked Sep 21 '19 13:09

Agnaramon


People also ask

What is ViewBinding?

View binding allows a developer to incorporate significant interaction in an application. This concept seeks to eliminate the findViewById keyword. Removing such boilerplate code allows developers to be more productive. A binding class is usually generated for each layout file when using view binding.

Can we use DataBinding and ViewBinding together?

You can't use them togheter in the same layout. ViewBinding is a subset of what DataBinding can do and should be used if you want to replace libraries like ButterKnife , KotterKnife or KAE (Kotlin Android Extensions) but don't want to invest in databinding refactoring.


2 Answers

As given in Official Website

Put it like:

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

Please check your Android Studio Version too, It must be 3.6 Canary 11+.

Also check Gradle Plugin - Android Gradle Plugin 3.6.0-alpha12

NOTE: View binding is available in Android Studio 3.6 Canary 11+.

like image 59
Pratik Butani Avatar answered Oct 21 '22 10:10

Pratik Butani


Some things have changed a little if you are using Android Gradle plugin >= 4.0.0-alpha05.

viewBinding.enabled = true is now deprecated

You should use the Android buildFeatures block instead:

android {
    buildFeatures {
        // Determines whether to support View Binding.
        // Note that the viewBinding.enabled property is now deprecated.
        viewBinding = true
    }
}

If you want the feature enabled by default in all of your modules you can turn on it in gradle.properties:

android.defaults.buildfeatures.viewBinding=true

Docs: https://developer.android.com/studio/preview/features/#4.0

like image 41
Guilherme V. Avatar answered Oct 21 '22 09:10

Guilherme V.