Androidx and databinding
S

6

14

I'm migrating my dependencies for an Android P test to the androidx dependencies. For some not very clear reasons my project does not compile anymore (and no I won't provide the details to avoid a distinct problem). I found out (via gradlew dependencies) that the databinding uses the "oldschool" dependency android.arch.lifecycle:runtime:1.0.3 instead of androidx.lifecycle:lifecycle-runtime:2.0.0-beta01. I guess that could be one reason.

Any idea how to force using the new package names/dependencies?

Sybarite answered 21/7, 2018 at 20:11 Comment(3)
Do you have android.enableJetifier=true and android.useAndroidX=true in gradle.properties?Sculpsit
@Sculpsit no I didn't use those flags. However setting those flags does not change the dependencies :/Sybarite
@Sculpsit making android.enableJetifier=true is not the real solution. It will increase build times. In worst cases RAM usage at every build will sky rocket(I have seen it using an extra 500mb myself). Instead it's better to manually migrate each of your libraries to androidx. This also gives you confidence over your code.Laminous
S
2

I tried that while I had a weak internet connection, so I skipped to update to Android Studio 3.2. That was my fault. With that upgrade (the unziping took almost an hour no idea why) I was requested also to upgrade my build tools to com.android.tools.build:gradle:3.2.0-beta04 (or whatever is the newest version matching for your Android Studio version (I would not install the 3.3.0-alpha03) and upgraded the gradle wrapper to 4.6.

Now the dependencies are gone and I'm happy.

Sybarite answered 29/7, 2018 at 19:0 Comment(0)
M
6

I face the similar problem, the Data Binding library use the support library, some classes may conflict with the AndroidX. I have to remove the DataBinding for now.

I just read this release note, it said that this issue had been fixed, but I didn't see the effect.

Muzhik answered 29/7, 2018 at 8:31 Comment(3)
relase note is saing: "Databinding libraries are not updated to androidx", I'm not sure how to understand that :DSarawak
I still face this error with a few support libraries like android.support.v4.widget does not exist. Any solution for this?Seymourseys
@Seymourseys Please post your code, I will look for the solution with you.Muzhik
T
6

Enabling AndroidX in the gradle.properties fixed this problem for me:

android.useAndroidX=true
android.enableJetifier=true

See https://developer.android.com/jetpack/androidx#using_androidx:

android.useAndroidX: When set to true, the Android plugin uses the appropriate AndroidX library instead of a Support Library. The flag is false by default if it is not specified.
android.enableJetifier: When set to true, the Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries. The flag is false by default if it is not specified.

Tarttan answered 12/4, 2019 at 6:57 Comment(0)
T
4

Check Layout files maybe there are Views left which use support library instead of androidx for example

<android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

change it to

<androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
Tirol answered 18/2, 2019 at 10:28 Comment(0)
S
2

I tried that while I had a weak internet connection, so I skipped to update to Android Studio 3.2. That was my fault. With that upgrade (the unziping took almost an hour no idea why) I was requested also to upgrade my build tools to com.android.tools.build:gradle:3.2.0-beta04 (or whatever is the newest version matching for your Android Studio version (I would not install the 3.3.0-alpha03) and upgraded the gradle wrapper to 4.6.

Now the dependencies are gone and I'm happy.

Sybarite answered 29/7, 2018 at 19:0 Comment(0)
L
2

1- Add this line into build.gradle

android {

    dataBinding {
        enabled = true
    }

}

2- gradle.properties(Project Properties)

android.databinding.enableV2=true
Lasky answered 20/6, 2019 at 7:13 Comment(1)
Readers please be aware that from android studio 3.2.0 and onwards this answer no longer applies. For the latest installation instructions refer to the 'Get started' page on the android developer site: developer.android.com/topic/libraries/data-binding/start .Heronry
P
1

In my case, the error was because the tool to migrate to AndroidX does not work perfectly. There was still some layout files using some old support libraries. After fixing those files, everything went well =)

To fix, every support library that was being used in those layout files, I changed to the right one following this link: https://developer.android.com/jetpack/androidx/migrate

Peripheral answered 9/12, 2018 at 16:27 Comment(3)
Which XML files were wrong, and how did you fix them ? Your answer will add more value if you provide these types of informationDuologue
@GMB, it was layout files. I just edited my answer to give more detailsPeripheral
Both yours and @Ahmad-Aghazadeh's were the answer; one has to hunt those references down!!Nagano

© 2022 - 2024 — McMap. All rights reserved.