Reputation: 5196
I'm trying to migrate my app to AndroidX, following the official doc. I run the refactor option: migrate to AndroidX.
At first I had errors that has been resolved by restarting and cleaning my project. I then had an issue STRING_TOO_LARGE
(cf. this Stack Overflow question) that I resolved by downgrading my gradle build tools to 3.1.3.
But now I'm struggling with databinding. The migration tool replaced all my
import android.databinding.**
by
import androidx.databinding.**
but I have the error message
cannot resolve androidx.databinding.
Is their any things I should do to get it working?
I tried to get back to the old databinding
by setting back
import android.databinding.**
Instead of the androidx
one but I then have an error with LiveData
used inside xml layout saying
cannot find the setter for attribute with parameter type androidx.lifecycle.MutableLiveData.
Upvotes: 3
Views: 11301
Reputation: 281
Add dataBinding true
in buildFeatures
Final Code:
buildFeatures {
viewBinding true
dataBinding true
}
Inside android block
Upvotes: 1
Reputation: 121
I had a similar issue after migrating to AndroidX. For me, I got an error when setting the contentView
for the activity, the rest of the Databinding code was deemed ok.
What worked for me, in the end, was to Invalidate Cache & Restart
. Sadly, that seems to be a common need when using AndroidStudio. Hopefully, they can get this fixed in time.
Upvotes: 0
Reputation: 71
Write below code in gradle
android {
...
dataBinding {
enabled = true
}
}
Upvotes: 6
Reputation: 58944
Data binding has very weird issue, that when you have some syntax error, or some imports error, it will show 100 of errors of binding, but not the actual error.
Open each xml file then java file of your work, and see if there are unresolved imports or errors. If you find some error, resolve and build project, Data binding classes only generate with successful build.
I have explained it well in my @this answer.
Upvotes: 1
Reputation: 21753
Androidx.databinding is the correct package, for future issues you can look up the mappings here: https://developer.android.com/jetpack/androidx/migrate#migrate.
Android Studio seems to be having a problem when switching branches or projects that are and aren't migrated though. At the moment the only fix working for me is to do a gradle clean and then restart android studio (either after switching branches or after migrating)
Upvotes: 1