【发布时间】:2019-07-19 09:58:30
【问题描述】:
请有人帮助我!我快疯了,这应该有效。当我尝试构建我的 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 文件 (full file here) 中定义 errorText 的方式:
object ViewDataBindingExtensions {
@JvmStatic
@BindingAdapter("errorText")
fun bindErrorText(textInputLayout: TextInputLayout, errorText: String) {
textInputLayout.error = errorText
}
}
我只是不明白为什么会这样。是否有某种导入可以放入布局文件中,说明 BindingAdapter 在哪里?我的 Gradle 文件有问题吗?我将它与this question 中的 GitHub 项目进行了比较,该项目显然得到了解决,我看不出与我的项目有什么不同。根据答案,我应该将 Kotlin-kapt 插件添加到我的 Gradle 构建中,我这样做了。我还查看了项目的其余部分并进行了比较。无济于事。您可以找到我的整个 build.gradle file here 以及项目的其余部分。
请帮帮我!
【问题讨论】:
-
你试过加
kapt "com.android.databinding:compiler:$gradleVersion"吗? -
@AntonHolovin 我现在试过了,但没有帮助。我假设我必须将它添加到应用程序项目的 build.gradle 中?并且版本应该与'com.android.tools.build:gradle:'的版本相同,对吗?那对我不起作用。但也许我做错了什么。我把它推到了 GitHub 你可以在链接下找到它github.com/findusl/OneNightComps/blob/feature/register/Android/…
-
我花了半个小时试图弄清楚这一点,却发现我错过了右括号。
android:text="@={viewModel.username"而不是android:text="@={viewModel.username}"
标签: android kotlin android-databinding androidx