Android数据绑定XML错误

前端之家收集整理的这篇文章主要介绍了Android数据绑定XML错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
每当我构建,运行,清理,重建等时,我都在 Android Studio项目上使用数据绑定库我收到以下错误
  1. :app:processDebugResources AGPBI:
  2.  
  3. {"kind":"error","text":"Error parsing XML: duplicate attribute","sources": [{"file":"C:\\Users\\lucia.beltran\\Desktop\\Picho\\Projects\\Personal\\ improved-tribble\\ImprovedTribble\\app\\build\\intermediates\\data-binding-layout-out\\debug\\ layout\\task_list_item.xml","position":{"startLine":16}}],"original":"","tool":"AAPT"}
  4.  
  5. C:\Users\lucia.beltran\Desktop\Picho\Projects\Personal\improved-tribble\ImprovedTribble\app\build\intermediates\data-binding-layout-out\debug\layout\task_list_item.xml:17: error: Error parsing XML: duplicate
  6.  
  7. Failed
  8.  
  9. FAILURE: Build Failed with an exception.
  10.  
  11. * What went wrong: Execution Failed for task ':app:processDebugResources'.
  12. > com.android.ide.common.process.ProcessException: Failed to execute aapt
  13.  
  14. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  15.  
  16. BUILD Failed
  17.  
  18. Total time: 3.826 secs

我的布局如下

  1. <layout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent">
  4.  
  5. <data>
  6. <variable
  7. name="task"
  8. type="com.pichardo.improvedtribble.models.Task" />
  9. </data>
  10.  
  11. <LinearLayout
  12. android:layout_width="match_parent"
  13. android:layout_height="match_parent"
  14. android:orientation="horizontal">
  15.  
  16. </LinearLayout>
  17.  
  18. </layout>

并且gradle控制台所说的绑定文件的布局如下:

  1. <LinearLayout
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent"
  4. android:orientation="horizontal" android:tag="layout/task_list_item_0" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">
  5.  
  6. </LinearLayout>

我得到了重复的属性,但我不知道为什么会崩溃.

我读了this question,但我的build.gradle文件中没有这样的东西.

有什么建议?

解决方法

尝试在布局标记删除android:layout_width和android:layout_height =“match_parent”
  1. <layout xmlns:android="http://schemas.android.com/apk/res/android">
  2.  
  3. <data>
  4. <variable
  5. name="task"
  6. type="com.pichardo.improvedtribble.models.Task" />
  7. </data>
  8.  
  9. <LinearLayout
  10. android:layout_width="match_parent"
  11. android:layout_height="match_parent"
  12. android:orientation="horizontal">
  13.  
  14. </LinearLayout>
  15.  
  16. </layout>

猜你在找的Android相关文章