I am trying to implement listener bindings, but when I run my code I get the following error:
Caused by: android.databinding.tool.util.LoggedErrorException: F
The error Cannot find the setter for attribute
means, it cannot find setter method that accepts the variable of the data type you provided as a parameter for that attribute.
That means it won't find the BindingAdapter method that you have defined. I had this issue because I was providing a wrong data type in XML layout to a custom attribute that I defined using BindingAdapter. Once I gave the correct data type to the custom attribute, it worked.
So, check if you are providing correct data type to the custom attributes that you may have defined using BindingAdapters.
Make sure apply plugin: 'kotlin-kapt'
is in build.gradle.
If you are running in to this and no amount of rebuilding the project, deleting directories, clearing AS settings do anything. The IDE is fine without having it but the building fails.
It would be nice if android studio had better error messages for this.
Valid case: This error is raised if you have an error in the xml file. First read carefully through the xml and if you find a problem fix it.
Invalid case: For me the issue was raised for a file that was already deleted from the project or the file was renamed and the databinding was referencing the old file.
I'm not sure how to get rid of the issue every time but I have a number of things that sometimes work and sometimes don't.
Fix number 1:
Running 'gradle wrapper' in the project root.
Fix number 2:
Android Studio Clean Project
Next delete these folders in the project root:
rm -rf .gradle/
rm -rf app/build/
rm -rf build
rm -rf gradle
rm -rf gradlew
Android Studio Invalidate and restart
Everything should be back to normal now.