Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android viewbinding deprecation warning persists in Android Studio 4 after making appropriate update

After updating to Androis Studio 4.0 I received a warning that android.viewBinding.enabled was deprecated and shoud lbe replaces with android.buildFeatures.viewBinding.

I therefoe changed the appropraiet part of my build.gradle (app) from:

android {
    ...
    viewBinding {
        enable = true
    }
    ...
}

to:

android {
    ...
    buildFeatures {
        viewBinding {
            enabled true
        }
    }
    ...
}

I no longer get the warning, but still get an information box in my build window as follows:

build.gradle: DSL element 'android.viewBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.viewBinding'. It will be removed in version 5.0 of the Android Gradle plugin.

Is this normal? I knows it's not a warning or an error, but it seems odd to tell me about something that has been fixed - or have I not fixed it correctly (my app still works using viewBinding as expected).

(Note also that when adding the buildFeatures section to the file, none of the required entires, including buildFeatures pops up in teh auto-complete prompt.)

Info item in Android Studio build panel

like image 688
Fat Monk Avatar asked Jun 01 '20 12:06

Fat Monk


People also ask

How to solve android Data Binding errors?

Three Methods for Solving Android Data Binding Errors 1 View All of the Build Output#N#Android Studio has two different ways to view the build output. The default tree view... 2 Fall Back to the Old Data Binding Compiler Temporarily#N#Starting in version 3.2.1 of Android Studio, the second... 3 Invalidate Caches More ...

What is viewbinding in Android Studio?

In Android Studio 4.0, viewBinding has been moved into buildFeatures [ release notes] and you should use: Once enabled for a project, view binding will generate a binding class for all of your layouts automatically.

Why is layout preview not working in Android Studio?

Android Studio layout preview stops working for native android.preference.Preference and custom preferences, when "androidx.preference:preference:1.1.0" is added Lint error with firebase-perf [OutdatedLibrary] even if we are using the latest version. Drawables with transparent shapes are not rendered correctly.

What happened to the Data Binding compiler in Android Studio?

Fall Back to the Old Data Binding Compiler Temporarily Starting in version 3.2.1 of Android Studio, the second version of the data binding compiler was turned on by default. Version 2 drastically improved compile times by incrementally creating the binding classes.


Video Answer


2 Answers

Solved it!

Although it was working - i.e. the View bindings were working fine - the correct new syntax appears to be:

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

...still not popping up in the auto-complete, though.


Update: After a few buids and rebuilds I checked again and now buildFeatures IS popping up in teh auto-complete... Guess I wasn't being patient enough for everything to catch up. Just a bit odd that invalidating the caches didn't fix the auto-complete straight away.

like image 195
Fat Monk Avatar answered Oct 06 '22 19:10

Fat Monk


@Fat Monk

Please add this line to your app build.gradle file.

android.buildFeatures.viewBinding = true
like image 43
Maulik Sinroja Avatar answered Oct 06 '22 21:10

Maulik Sinroja