如何在 string.xml 文件中找到所有虚假或无用的字符串值?

How can I find all fake or useless string values in string.xml file?

我有一个大而杂乱的 string.xml 文件,其中包含 3000 条记录,其中大部分值都是无用的,并且从未在代码中使用过。我想自动查找并忽略那些无用的记录。有没有办法在 string.xml 文件中找到无用的记录?

菜单 -> 分析 -> 运行 按名称检查 -> 未使用的资源

实际资源Is there any simple way to find out unused strings in Android project?

在 Android Studio 中使用(删除未使用的资源) link

我建议最好的方法是将 XML 加载到 Python ElementTree 等对象中。 导入 xml.etree.ElementTree 然后,您可以轻松地修剪所有分支,然后再导出为 XML 文件。在字符串级别处理 XML 很麻烦。

右键单击 strings.xml 文件: 单击 Refractor,然后单击 Remove Unused Resources。 点击确认对话框中的Refractor

我发现使用 lint 检查和 t运行slations 编辑器非常有效。

转到分析 -> 运行 按名称检查 -> 未使用的资源。

这里我添加了一个文件掩码只显示字符串

检查 运行 后转到 Translations Editor,找到密钥,右键单击并安全删除。

可以安全地删除此资源检查并删除所有语言环境中的密钥。