8

I have already updated gradle.properties file adding:

android.useAndroidX=true
android.enableJetifier=true

But i have this error:

e: [kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: failure, see logs for details.
AndroidX Error: Both old and new data binding packages are available in dependencies. Make sure you've setup jettifier  for any data binding dependencies and also set android.useAndroidx in your gradle.properties file.
    at android.databinding.tool.util.L.printMessage(L.java:134)
    at android.databinding.tool.util.L.e(L.java:107)
    at android.databinding.tool.Context.discoverAndroidX(Context.kt:62)
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
AJit
  • 1,283
  • 1
  • 13
  • 34

6 Answers6

2

Even if you enable the use of AndroidX

android.useAndroidX=true
android.enableJetifier=true

and databinding

android {
    ...
    ...
    dataBinding {
        enabled = true
    }

}

you will still have problems related to dependencies.

I suggest to you, refactoring and changing automatically all the necessary imports to Android X to avoid this kind of problems.

Select your project, go yo Refactor > Migrate to AndroidX

enter image description here

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
0

AndroidX Error: Both old and new data binding packages are available in dependencies.

This error means that you have not yet converted all your old dependencies to their new respective dependency.

This official page has a list of artifact mappings. You need to identify your old dependencies and change it to new as mapped in above page.

For example -

com.android.support:cardview-v7 is available in androidx.cardview:cardview:1.0.0 com.android.support:support-v4 - androidx.legacy:legacy-support-v4:1.0.0

once you change all dependencies to new artifacts then your error will resolve. If you need to know about AndroidX, here is an detailed answer.

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
  • I had this issue pop up after my project was refactored to use AndroidX through the respective option in Android Studio. It caught all the old support libraries and replaced it with the respective AndroidX artifacts. I don't think it was this. (Admittedly, my case left Jetifier off due to the project using a no-longer supported library that has an annotation processor. I'd remove it if I could.) – MowDownJoe Aug 06 '19 at 12:59
0
android.databinding.enableV2=true

add this line to your gradle.properties file.

Also, snippet of your build.gradle (app) file would be much helpful.

Anubhav Malik
  • 242
  • 7
  • 13
0

When this happens after migrating... just delete the build directories, which hold the generated sources (even if all of the artifacts had been replaced in the build.gradle, the generated data-bindings may still be present in these sources - causing that duplicate warning).

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
0

in my case i just removed implementation 'androidx.databinding:databinding-compiler:3.5.3'

gor
  • 1,046
  • 1
  • 14
  • 28
0

I had the same error and it got resolved when I removed this line (implementation 'androidx.databinding:databinding-compiler:3.6.0') from my dependencies in app/build.gradle. Hope this helps