1

I have migrated my code to AndroidX. Things are working fine except databinding.

I am getting the following error

Databinding errors after migrating to AndroidX

"Error:Cannot resolve the package androidx.databinding"

As of now, I have added the following lines in the Gradle build

 dataBinding {
enabled = true}

And in gradle.properties,

android.useAndroidX=true
android.enableJetifier=true

I have gone through a lot of links for the same. But didn't help.

Androidx and databinding AndroidX incompatible with DataBinding Android and so on.

Is there any solution for this?

Zulqarnain
  • 611
  • 7
  • 18
Catcaty
  • 63
  • 1
  • 8

2 Answers2

1

Finally, I found answer to my question.

My App has 2 modules and I used Data binding in both. After migrating to AndroidX, one of the modules had not been converted to AndroidX (Data Binding import statements only). So this was my issue.

Solution: There are Two gradle.properties files if we see properly.

  1. Project Structure -> gradle.properties
  2. Android Structure -> Gradle Scripts - > gradle.properties

I migrated from Android to AndrodX through Refactor--> Migrate to AndroidX. Then following two lines have been added to 2nd gradle.properties(Android Structure -> Gradle Scripts - > gradle.properties).

android.enableJetifier=true
android.useAndroidX=true

So the other module was not converted to AndroidX (Only Data Binding). Then the same 2 lines i have added in 1st gradle.properties (Project Structure -> gradle.properties).

Then my project could build successfully.

Thanks.

Catcaty
  • 63
  • 1
  • 8
0

Try add android.databinding.enableV2=true in the gradle properties file Androidx and databinding are compatibles