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.)
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 ...
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.
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.
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.
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.
@Fat Monk
Please add this line to your app build.gradle file.
android.buildFeatures.viewBinding = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With