Just migrated to AndroidX and this error has appeared when trying to build:
Unknown class: java.lang.String
file://----/app/src/main/res/layout/my_fragment.xml Line:XXX
The line in question is the start of an EditText which uses two-way databinding:
android:text="@={viewModel.myString}"
myString
looks like this:
val myString = MutableLiveData<String>()
I have multiple instances of this; each one involves two-way data binding in an EditText with a LiveData<String>
.
Layout Binding expressions Expressions in the XML layout files are assigned to a value of the attribute properties using the “ @{} " syntax. We just need to use the basic syntax @{} in an assignment expression.
Stay organized with collections Save and categorize content based on your preferences. The @={} notation, which importantly includes the "=" sign, receives data changes to the property and listen to user updates at the same time. // Avoids infinite loops.
For those having this issue with databinding v3.4.0, a temporary rollback to 3.3.2 fixed it for me. I posted an issue about this on their tracker in the meantime.
To rollback, all you have to do is change your build.gradle
accordingly:
android {
...
dataBinding {
enabled = true
version = '3.3.2'
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With