是否有工具可以在Android项目中查找未使用的资源?

时间:2011-04-28 20:09:18

标签: android resources find

我想在Android项目中找到任何未使用的资源 - 包括字符串,id,drawable,整数等。

目前是否存在执行此操作的工具(最好是Eclipse)?

5 个答案:

答案 0 :(得分:34)

友情提示:IntelliJ构思仅适用于JAVA代码中未引用的资源。因此,如果您有1500个资源,并且只有20个资源直接从您的Java代码中引用,那么您最终会在该文件中发出1480个未使用的警告。

我看到标记为未使用的东西,我可以清楚地看到它们正在各种布局中使用。所以记住这一点......不要继续删除狂欢。

答案 1 :(得分:34)

更新到ADT 16并使用Android Lint。这真是一个了不起的工具。

  

Android Lint是ADT 16(和工具16)的新工具,它可以扫描Android项目源中的潜在错误。

Here are some examples of the types of errors that it looks for:

- Missing translations (and unused translations)
- Layout performance problems (all the issues the old layoutopt tool used to find, and more)
- Unused resources
- Inconsistent array sizes (when arrays are defined in multiple configurations)
- Accessibility and internationalization problems (hardcoded strings, missing contentDescription, etc)
- Icon problems (like missing densities, duplicate icons, wrong sizes, etc)
- Usability problems (like not specifying an input type on a text field)
- Manifest errors
and many more.

答案 2 :(得分:19)

Andrei Buneyeu是正确的Android Lint是要走的路。要专门回答任何其他人的问题,命令是:

lint --check UnusedResources <path to project>

使用lint --list可以看到lint中有更多选项。

答案 3 :(得分:18)

如果您使用在免费社区版中具有Android支持的IntelliJ,您可以通过打开生成的R.java文件(gen / R.java)来完成此操作。未使用的资源将标记为警告,以便在项目的任何位置都不被引用。

如果Eclipse没有做同样的事情,我会感到惊讶。

答案 4 :(得分:5)

android-unused-resources是一个Java工具,可以检测未使用的资源,并告诉您它们的位置。它处理Java和XML文件,因此它避免了接受的答案中的问题。

这并不完美,但只要你不动态加载资源(getIdentifierjava.lang.String, java.lang.String, java.lang.String)),它就不应该告诉你删除任何实际使用的资源(尽管你即使发生了这种情况,也会出现编译错误。