确定是否不再使用诸如 strings.xml 中的资源

发布于 2024-10-03 10:11:36 字数 136 浏览 3 评论 0原文

我已经对我的 Android 程序之一进行了一些重要的重新编码,现在我不确定是否不再使用某些 xml 字符串。此外,我还有一些翻译,这使得任务变得更加困难。有没有工具可以测试这个?这对于可绘制对象也很有用。

我正在使用 eclipse 插件。

I have done some significant re-coding on one of my Android programs and now I am unsure if certain xml strings are used anymore. In addition I have a few translations which makes the task even more difficult. Is there a tool to test this? This would be useful for drawables also.

I am using the eclipse plugin.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

肩上的翅膀 2024-10-10 10:11:36

这个问题之前在irc频道里讨论过。没有工具可以测试它,但我同意它会很有用。请注意,资源可以在 xml 中引用,但也可以从代码中引用。此外,资源还可以通过其标识符来查找,并且这种查找可以由运行时确定。

所以实际上你不能100%确定某个资源是否被使用,但你可能可以确定以静态方式(在xml或代码中)引用了哪些资源。根据您最了解的代码/应用程序,这种方法在许多情况下可能就足够了。

方法是编写一个工具来解析 xml 和 java 源文件,并考虑 import 语句。有了这些信息,您应该能够确定可以摆脱哪些资源。

This question has been discussed in the irc channel before. There is no tool to test it, but I agree it would be useful. Note that resources can be referenced in xml, but they can also be referenced from code. Furthermore, resources can also be looked up by their identifier, and such lookup could be determined by runtime.

So actually you cannot determine 100% whether a resource is used or not anymore, but you can probably determine which resources are referenced in a static way (in xml or code). Depending on your code/app which you know best yourself, such approach might be sufficient in many cases.

The approach would be to write a tool that parses xml and java source files and also take the import statements into consideration. With that information you should be able to determine which resources you can get rid of.

走过海棠暮 2024-10-10 10:11:36

最简单的方法是将它们全部删除,尝试编译,然后重新添加编译器认为缺少的内容。这有点烦人,但确实很容易处理。

请注意,正如马蒂亚斯已经指出的那样,从技术上讲,在运行时通过字符串名称访问资源是可能的,我在这里建议的方法将删除这些资源,尽管它们实际上是需要的。然而,这种模式在任何应用程序中都应该很少见,如果您是编写它的人,您已经知道是否/在哪里进行这种处理。

The easiest way is to remove them all, attempt to compile, and re-add those the compiler says are lacking. It's a little tiresome, but it's certainly tractable.

Note, as Mathias already pointed out, that it's technically possible to access resources by name with a string at runtime, and the way I suggest here would remove such resources though they are, in fact, needed. However, this pattern should be really rarely seen in any application, and if you are the one who wrote it, you already know if/where you do such treatment.

寂寞笑我太脆弱 2024-10-10 10:11:36

使用 grep 通过排序将资源列表提取到文件中

使用递归 grep 通过排序和 uniq 创建任何源文件中提到的资源列表(复制没有未使用的文件的项目,或将 grep 分派到已使用的文件列表上)的,当然注释掉的代码将是一个问题)

在两个列表上使用 diff

Use grep to extract a list of resources to a file by way of sort

Use recursive grep through sort and uniq to create a list of those mentioned in any source file (make a copy of project without unused files or dispatch grep on a list of used ones, of course commented out code will be an issue)

Use diff on the two lists

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文