Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown class: java.lang.String in AndroidX two-way data binding

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

like image 703
P. Bryant Avatar asked Aug 08 '18 10:08

P. Bryant


People also ask

Which is the correct way to reference bound data in the XML layout?

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.

What is 2 way Data Binding in Android?

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.


1 Answers

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'
        }
    ...
}
like image 105
Vrakfall Avatar answered Nov 12 '22 01:11

Vrakfall