Android 未找到绑定适配器

Android Binding Adapter is not found

请有人帮助我!我快疯了,这应该行得通。当我尝试构建我的 Android 项目时出现以下错误消息:

Android resource linking failed
/Users/slehrbaum/StudioProjects/OneNightComps/Android/app/build/intermediates/incremental/mergeDebugResources/stripped.dir/layout/fragment_login.xml:17: error: attribute errorText (aka lehrbaum.de.onenightcomps:errorText) not found.
error: failed linking file resources.

错误消息确实提到了 errorText 属性。我以这种方式在 xml 中使用 errorText 属性 (full xml here):

<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/usernameField"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/username"
        app:hintEnabled="true"
        app:errorEnabled="true"
        app:errorText="Hi"
        >
        <!--app:errorText="Please provide a username."-->
        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:autofillHints="username"
            android:inputType="text"
            android:text="@={viewModel.username}"
            />
    </com.google.android.material.textfield.TextInputLayout>

这是我在 Kotlin 文件中定义 errorText 的方式 (full file here):

object ViewDataBindingExtensions {
    @JvmStatic
    @BindingAdapter("errorText")
    fun bindErrorText(textInputLayout: TextInputLayout, errorText: String) {
        textInputLayout.error = errorText
    }
}

我只是不明白为什么会这样。我可以在布局文件中放置某种导入,说明 BindingAdapter 的位置吗?我的 Gradle 文件有问题吗?我将它与 this question which apparently got solved and I do not see the difference to my project. According to the answer I should add the Kotlin-kapt plugin to my Gradle build, which I did. I also looked through the rest of the project and compared. To no avail. You can find my whole build.gradle file here 中的 GitHub 项目以及项目的其余部分进行了比较。

请帮帮我!

尝试使用

fun bindErrorText(textInputEditText: TextInputEditText, errorText: String) {
 textInputEditText.error = errorText }

问题与您将字符串值传递给 app:errorText 的方式有关。

使用@{``} 传递这个值。

fragment_login.xml 的固定部分:

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/username"
    app:hintEnabled="true"
    app:errorText="@{`Please provide a username.`}"
    app:errorEnabled="@{!viewModel.usernameValid}">

app/build.gradle 中有 apply plugin: 'kotlin-kapt' 是强制性的。