我想删除所有未使用的布局,字符串,绘图,颜色等从我的Android res目录。是否有任何工具可以给我一个文件列表,我可以从我的存储库中删除特定文件中的元素(例如未使用的字符串条目),这些文件不再使用?


当前回答

我们开源了一个工具,可以根据lint输出删除android项目中所有未使用的资源。 可以在这里找到:https://github.com/KeepSafe/android-resource-remover

其他回答

如果你在使用多种香料时要小心。根据你所选择的口味,棉绒可能会给出虚假的未使用的资源。

由于Eclipse中对ADT的支持已经结束,我们不得不使用Android Studio。

在Android Studio 2.0+使用Refactor >删除未使用的资源…

自从ADT 16以来,你可以使用Android Lint。这真是个神奇的工具。

Android Lint is a new tool for ADT 16 (and Tools 16) which scans Android project sources for potential bugs. 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.

然而,它有一些问题(不知道它们是否已经修复),如果你想删除数百个据称未使用的资源,我建议在资源删除期间手动编译项目几次,以确保Lint没有删除所需的东西。

你可以很容易地从Android Studio搜索未使用的资源。只需按下CtrlAltShifti并输入“未使用的资源”(不带引号)。将执行lint。超级简单的方法运行lint命令(和其他东西从IDE)。

OR

在Android Studio菜单>重构>删除未使用的资源…

选择要删除的资源。通过右键单击资源项,可以排除想要保留的资源。

使用Do Refactor一次性删除所有资源。

更新:mac使用⌘OptionShifti

在Android Studio中运行Lint并找到所有未使用的资源后,您可以从Inspection选项卡中单击其中一个。它提供了关于该问题的一些详细信息以及修复该问题的一些选项。其中之一是删除所有未使用的资源。选择该选项将删除所有未使用的资源。