Androidx and databinding

∥☆過路亽.° 提交于 2019-11-29 09:34:37

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.

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.

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.

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">

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

1- Add this line into build.gradle

android {

    dataBinding {
        enabled = true
    }

}

2- gradle.properties(Project Properties)

android.databinding.enableV2=true
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!