【问题标题】:Duplicate Resources: Is there a way to ignore the duplicate resource automatically while building in android studio重复资源:有没有办法在android studio中构建时自动忽略重复资源
【发布时间】:2018-12-09 20:12:48
【问题描述】:

我有 2 个 res 文件夹,但不在同一路径中,并且每个 res 文件夹都有一个 values 文件夹。
在 values 文件夹中,有一个“string.xml”文件。 (见下图)。 在每个“string.xml”文件中,都有两个定义类似的字符串名称。当我构建项目时,我得到这个错误:

错误:任务“:app:mergeDebugResources”执行失败。
[string/app_name] E:\AndroidStudioProjects\test\app\src\main\res\values\strings.xml [string/app_name] E:\AndroidStudioProjects\test\app\src\main\java\com\example\quywn \test\res\values\string.xml:错误:资源重复

当然只有 2 个 string.xml 文件,我可以手动重命名或删除它,但是当我有很多文件与上述相同的错误时,我无法手动重命名或删除它们。所以我的问题是“有没有办法重命名/删除重复资源中的内容或忽略重复资源并自动选择1个相同的内容?”

例如:我在每个 string.xml 中有 2 个具有相同定义的字符串名称的 string.xml。构建时,系统检查 2 个文件 string.xml 并仅选择 1 个字符串名称并忽略另一个,尽管 2 个字符串名称中的一个没有被删除或重命名。而此时,我希望不会发生错误并成功构建。

Project Structure

The content of the first string.xml

The content of the second string.xml

【问题讨论】:

    标签: android xml duplicates resources


    【解决方案1】:

    我认为你想做一些类似的事情来在 android 中添加多语言支持。 您在 string.xml 中有相同的字符串名称,并且您想使用其中之一。看这个 link,它可能会帮助你。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-13
      • 2017-04-18
      • 1970-01-01
      • 1970-01-01
      • 2019-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多