DataBinding BindingAdapter in library project is not applied

Viewed 609

I am creating a multi-module project. I want to share BindingAdapter in modules. But, The following error occurs.

com.github.takahirom.bindingadapter_in_library.databinding
e: [kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding errors.
****/ data binding error ****msg:Cannot find the setter for attribute 'app:customText' with parameter type java.lang.String on android.widget.TextView. file:/Users/takahirom/git/bindingadapterinlibrary/app/src/main/res/layout/content_main.xml loc:16:34 - 16:47 ****\ data binding error ****

    at android.databinding.tool.processing.Scope.assertNoError(Scope.java:112)
    at android.databinding.annotationprocessor.ProcessDataBinding.doProcess(ProcessDataBinding.java:109)
    at android.databinding.annotationprocessor.ProcessDataBinding.process(ProcessDataBinding.java:73)
    at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:99)

This is the sample project. https://github.com/takahirom/databinding-in-library-sample

app module https://github.com/takahirom/databinding-in-library-sample/blob/master/app/src/main/res/layout/content_main.xml

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:customText="@{`Hello World!`}"

library module https://github.com/takahirom/databinding-in-library-sample/blob/master/library/src/main/java/TestBinding.kt (If I put this file in the app module, The error does not occur)

@BindingAdapter("app:customText")
fun customText(textView: TextView, text: String) {
    textView.text = "** $text **"
}
1 Answers

Use this instead

@BindingAdapter("customText")

The name space is not considered in binding adapter

Related