我正在创建一个多模块项目。 我想在模块中共享BindingAdapter。 但是,发生以下错误。
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)
这是示例项目。 https://github.com/takahirom/databinding-in-library-sample
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:customText="@{`Hello World!`}"
库模块https://github.com/takahirom/databinding-in-library-sample/blob/master/library/src/main/java/TestBinding.kt(如果我将此文件放在app模块中,则不会发生错误)
@BindingAdapter("app:customText")
fun customText(textView: TextView, text: String) {
textView.text = "** $text **"
}
答案 0 :(得分:0)
改为使用此
@BindingAdapter(“ customText”)
绑定适配器中不考虑名称空间