Android XML: "conflicts with another tag that has the same ID"
Android XML: "conflicts with another tag that has the same ID"
我最近从我的项目中删除了一个片段,包括它的布局和视图模型。 (FragmentAddFlight, VmAddFlight, fragment_add_flight.xml)
令人惊讶的是我收到了这些错误:
[databinding] {"msg":"\u003cImageView id\u003d\u0027@+id/imageView2\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":277,"col0":20,"line1":286,"col1":85}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView4\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":308,"col0":28,"line1":312,"col1":64}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/editText8\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":314,"col0":28,"line1":318,"col1":60}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView5\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":327,"col0":28,"line1":331,"col1":63}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView14\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":333,"col0":28,"line1":338,"col1":57}]}
[databinding] {"msg":"\u003cImageView id\u003d\u0027@+id/imageView2\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":369,"col0":20,"line1":378,"col1":72}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView4\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":400,"col0":28,"line1":404,"col1":60}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/editText8\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":406,"col0":28,"line1":410,"col1":60}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView5\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":419,"col0":28,"line1":423,"col1":71}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView14\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":425,"col0":28,"line1":430,"col1":57}]}
[databinding] {"msg":"\u003cImageView id\u003d\u0027@+id/imageView2\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":452,"col0":20,"line1":461,"col1":77}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView4\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":483,"col0":28,"line1":487,"col1":60}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/editText8\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":489,"col0":28,"line1":493,"col1":60}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView5\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":502,"col0":28,"line1":506,"col1":71}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView14\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":508,"col0":28,"line1":513,"col1":57}]}
记住这些错误中引用的文件已经被删除。为什么会出现这些错误?
我通过 Build -> clean project 清理了项目。我试图通过相同的菜单重建项目。但是结果还是一样。
有人知道如何解决这个问题吗?
这些文件是在编译时创建的,因此它们可能没有被删除,请尝试使缓存无效并在 android studio 中重新启动。
要添加有关如何使缓存无效的信息,请在 Android Studio 中转到文件 > 使缓存无效/重新启动 > 使缓存无效并重新启动
Invalidate Caches/Restart
选项有时不起作用。
gradlew assembleDebug
只需尝试此命令,然后查看问题将不再可用。
编译时间问题:
固定的:
1.Clean 项目。
2.clear 缓存并重启。
确保视图绑定已启用。
如果您使用视图绑定,您可以将其添加到布局中,直到您拥有更好的视图 ID:
tools:viewBindingIgnore="true"
对每个有问题的布局执行此操作。
我从 here 中找到了这个提示。
可能是您不小心创建了一个 layout-26 文件夹,里面有两个 XML 个同名文件。
解决方案-:
1.Move从layout-26文件夹到layout文件夹的正确XML文件
2.Delete layout-26 文件夹。
有时 none 上述技巧会按预期工作。使缓存无效并重新启动 Android Studio 对我来说根本不起作用。我也尝试了以下命令
gradlew assembleDebug
但是只能用一次。每次更改布局文件时我都必须这样做。如果 none 对您有用,请尝试遵循这些技巧
- 重命名布局文件。您可能还想更改绑定 class
- 将项目导出为 zip,将其解压缩到不同位置并打开现有项目。
None 以上对我有用:tools:viewBindingIgnore="true" , invalidate caches, gradlew assembleDebug
。一切都不行。
我找到的唯一方法是删除整个项目并从git中重新拉取源代码。然后构建 -> 它 运行 正常
如果File > Invalidate Caches / Restart > Invalidate and Restart
无法解决您的问题。也许你可以试试
- 删除
buildFeatures {
dataBinding = true
}
- 无效
- 关闭 AndroidStudio
- 如果你的系统是
Windows
,打开resource monitor
(因为我的电脑是中文的,所以不知道英文系统怎么翻译这个词。打开cmd
,输入perfmon
,就可以看到了。)
- 点击
CPU
->Associated handle
->搜索android
.
- 关闭所有关联句柄,然后打开您的 AndroidStudio 并添加
buildFeatures {
dataBinding = true
}
在我的例子中,我的 XML 文件中的不同视图分配了相同的 ID。
我只是更改了其中一个以避免冲突然后它起作用了。
我最近从我的项目中删除了一个片段,包括它的布局和视图模型。 (FragmentAddFlight, VmAddFlight, fragment_add_flight.xml)
令人惊讶的是我收到了这些错误:
[databinding] {"msg":"\u003cImageView id\u003d\u0027@+id/imageView2\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":277,"col0":20,"line1":286,"col1":85}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView4\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":308,"col0":28,"line1":312,"col1":64}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/editText8\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":314,"col0":28,"line1":318,"col1":60}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView5\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":327,"col0":28,"line1":331,"col1":63}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView14\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":333,"col0":28,"line1":338,"col1":57}]}
[databinding] {"msg":"\u003cImageView id\u003d\u0027@+id/imageView2\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":369,"col0":20,"line1":378,"col1":72}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView4\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":400,"col0":28,"line1":404,"col1":60}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/editText8\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":406,"col0":28,"line1":410,"col1":60}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView5\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":419,"col0":28,"line1":423,"col1":71}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView14\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":425,"col0":28,"line1":430,"col1":57}]}
[databinding] {"msg":"\u003cImageView id\u003d\u0027@+id/imageView2\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":452,"col0":20,"line1":461,"col1":77}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView4\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":483,"col0":28,"line1":487,"col1":60}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/editText8\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":489,"col0":28,"line1":493,"col1":60}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView5\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":502,"col0":28,"line1":506,"col1":71}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView14\u0027\u003e conflicts with another tag that has the same ID","file":"C:\Users\Christoph\Documents\Android-Projekte\FlightLogger\app\src\main\res\layout\fragment_add_flight.xml","pos":[{"line0":508,"col0":28,"line1":513,"col1":57}]}
记住这些错误中引用的文件已经被删除。为什么会出现这些错误?
我通过 Build -> clean project 清理了项目。我试图通过相同的菜单重建项目。但是结果还是一样。
有人知道如何解决这个问题吗?
这些文件是在编译时创建的,因此它们可能没有被删除,请尝试使缓存无效并在 android studio 中重新启动。
要添加有关如何使缓存无效的信息,请在 Android Studio 中转到文件 > 使缓存无效/重新启动 > 使缓存无效并重新启动
Invalidate Caches/Restart
选项有时不起作用。
gradlew assembleDebug
只需尝试此命令,然后查看问题将不再可用。
编译时间问题: 固定的: 1.Clean 项目。 2.clear 缓存并重启。
确保视图绑定已启用。
如果您使用视图绑定,您可以将其添加到布局中,直到您拥有更好的视图 ID:
tools:viewBindingIgnore="true"
对每个有问题的布局执行此操作。
我从 here 中找到了这个提示。
可能是您不小心创建了一个 layout-26 文件夹,里面有两个 XML 个同名文件。
解决方案-:
1.Move从layout-26文件夹到layout文件夹的正确XML文件
2.Delete layout-26 文件夹。
有时 none 上述技巧会按预期工作。使缓存无效并重新启动 Android Studio 对我来说根本不起作用。我也尝试了以下命令
gradlew assembleDebug
但是只能用一次。每次更改布局文件时我都必须这样做。如果 none 对您有用,请尝试遵循这些技巧
- 重命名布局文件。您可能还想更改绑定 class
- 将项目导出为 zip,将其解压缩到不同位置并打开现有项目。
None 以上对我有用:tools:viewBindingIgnore="true" , invalidate caches, gradlew assembleDebug
。一切都不行。
我找到的唯一方法是删除整个项目并从git中重新拉取源代码。然后构建 -> 它 运行 正常
如果File > Invalidate Caches / Restart > Invalidate and Restart
无法解决您的问题。也许你可以试试
- 删除
buildFeatures {
dataBinding = true
}
- 无效
- 关闭 AndroidStudio
- 如果你的系统是
Windows
,打开resource monitor
(因为我的电脑是中文的,所以不知道英文系统怎么翻译这个词。打开cmd
,输入perfmon
,就可以看到了。) - 点击
CPU
->Associated handle
->搜索android
. - 关闭所有关联句柄,然后打开您的 AndroidStudio 并添加
buildFeatures {
dataBinding = true
}
在我的例子中,我的 XML 文件中的不同视图分配了相同的 ID。 我只是更改了其中一个以避免冲突然后它起作用了。