Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio fails to generate databinding after 3.1.0 update

This morning I made an update to android studio from 3.0.1 to 3.1.0. After updating the gradle to latest version I still get build error regarding data binding.

My gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 

All my errors are like the one below:

/Users/mp/Documents/GitHub/projectx/app/build/generated/source/dataBinding/baseClasses/Staging/debug/me/projectx/asdasd/databinding/GridItemActivityTypeBinding.java:57: error: cannot find symbol       @Nullable DataBindingComponent component) {                 ^   symbol:   class DataBindingComponent   location: class GridItemActivityTypeBinding 

Does anyone have any idea why would my data binding not generate after the android studio 3.1 update? Thanks in advance

Edit 1: Forgot to say, I tried clean/rebuild/invalidate cache & restart/deleted build folder.

like image 281
Marian Pavel Avatar asked Mar 27 '18 13:03

Marian Pavel


People also ask

Is Android databinding deprecated?

Recently Android has announced that with Kotlin 1.4. 20, their Android Kotlin Extensions Gradle plugin will be deprecated and will no longer be shipped in the future Kotlin releases. Android Kotlin Extensions plugin brought with it two very cool features : Synthetics let you replace calls to findViewById with kotlinx.

What is difference between Viewbinding and Databinding in Android?

View binding and data binding both generate binding classes that you can use to reference views directly. However, view binding is intended to handle simpler use cases and provides the following benefits over data binding: Faster compilation: View binding requires no annotation processing, so compile times are faster.

Can we use databinding in MVP?

Why use Data binding with Mvp? Combining Databinding along wih MVP pattern can result in a very clean structure and maintainable project. Databinding saves u a lot of stress and uneccesary long lines of code. Your UI is updated eaily and gone are those days where you need "findViewById" and onclick listeners and so on.

How do I use Android databinding?

To convert your XML layouts into the Data Binding layout, follow the below steps: Declare a <layout> tag, which will wrap your existing layout file at the root level. Declare variables under the <data> tag, which will go under the <layout> tag. Declare necessary expressions to bind data inside the view elements.


2 Answers

Following the update to Android Studio 3.2, this line works for me. I have both Java and Kotlin code (compiler) running in my project.

Add the following to your gradle.properties: android.databinding.enableV2=false

Reason:

Data Binding V2

Data Binding V2 is now enabled by default and is compatible with V1. This means that, if you have library dependencies that you compiled with V1, you can use them with projects using Data Binding V2. However, note that projects using V1 cannot consume dependencies that were compiled with V2.

source (Release Note): https://developer.android.com/studio/releases/

like image 105
Xavier Avatar answered Oct 14 '22 18:10

Xavier


Just Commenting these lines out in graddle-wrapper.properties file helped me solve my problem

#android.enableExperimentalFeatureDatabinding = true #android.databinding.enableV2=true 
like image 25
Barungi Stephen Avatar answered Oct 14 '22 16:10

Barungi Stephen