我最近从我的项目中删除了一个片段,包括其布局和视图模型。 (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}]}
请记住这些错误中引用的文件已被删除。为什么我会收到这些错误?
我通过“构建”->“清理项目”清理了项目。我尝试通过相同的菜单重建项目。但结果还是一样。
有人知道如何解决这个问题吗?
这些文件是在编译时创建的,因此它们可能没有被删除,请尝试使缓存无效并在 android studio 中重新启动。
Invalidate Caches/Restart
选项有时不起作用。
gradlew assembleDebug
只需尝试此命令,然后看到问题将不再可用。
要添加如何使缓存无效,请在 Android Studio 中转到“文件”>“使缓存无效/重新启动”>“无效并重新启动”
如果
File > Invalidate Caches / Restart > Invalidate and Restart
无法解决您的问题。也许你可以尝试一下
buildFeatures {
dataBinding = true
}
Windows
,打开resource monitor
(因为我的电脑是中文的,所以不知道这个词在英文系统中怎么翻译。打开cmd
,输入perfmon
,你就会看到它。)CPU
->Associated handle
->搜索 android
。 buildFeatures {
dataBinding = true
}
有时,上面解释的技巧都不能按预期工作。无效缓存和重新启动 Android Studio 对我来说根本不起作用。我也尝试了以下命令
gradlew assembleDebug
但它只能起作用一次。每次更改布局文件时我都必须执行此操作。如果这些技巧都不适合您,请尝试遵循这些技巧
在我的例子中,我的 XML 文件中的不同视图分配了相同的 ID。 我只是更改了其中一个以避免冲突,然后它就起作用了。
编译时问题: 固定的: 1.清理项目。 2.清除缓存并重新启动。
确保视图绑定已启用。
可能是您不小心创建了一个layout-26文件夹,其中有两个同名的XML文件。
解决方案-:
1.将正确的XML文件从layout-26文件夹移动到layout文件夹
2.删除layout-26文件夹。
如果您遇到此类问题,请按照以下说明操作
如果您的系统是Windows,
现在你发现没有这样的错误了。 这个过程对我来说很有效。
如果不终止现有的 Gradle 进程就无法让它运行。
在 Linux 终端上:
pkill -f '.*GradleDaemon.*'
有时,当您在当前文件中重构(重命名)id 并更改整个项目中的 id 时,就会出现此问题..
xml 布局中 id 的任何声明都应该是唯一的。
这将在您的应用程序中是全局的:
<LinearLayout
android:id="@+id/myLayoutId"
虽然这不会是全球性的
<LinearLayout
android:id="@id/myLayoutId"
通常不会有问题,但要记住一些事情。
正确的解决方案就在这里。
第 1 步:从 build.gradle 文件中删除此行
buildFeatures {
dataBinding = true
}
第2步:缓存无效并重新启动android studio 第3步:关闭Android Studio 第4步:完成第2步后让android studio同步 第 5 步:重新启动系统
还有 woilaa..!!
以上都不适合我:
tools:viewBindingIgnore="true" , invalidate caches, gradlew assembleDebug
。一切都行不通。
我发现的唯一方法是删除整个项目并再次从git中拉取源代码。然后构建 -> 正常运行