Androidx and databinding

2019-02-21 17:57发布

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?

4条回答
叼着烟拽天下
2楼-- · 2019-02-21 18:14

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.

查看更多
疯言疯语
3楼-- · 2019-02-21 18:23

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.

查看更多
啃猪蹄的小仙女
4楼-- · 2019-02-21 18:26

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

查看更多
女痞
5楼-- · 2019-02-21 18:35

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">
查看更多
登录 后发表回答