Android中未使用的字符串和图像资源

use*_*789 34 android

我的项目有大量的String和ImageResources,其中许多我认为是未使用的.有什么方法可以找出我的代码当前没有引用这些资源中的哪些?

Ale*_*ang 82

在Android Studio(试用到2.1.3版)中,您只需转到主菜单 - >分析 - >按名称运行检查...,然后选择未使用的资源

在此输入图像描述

(它为你运行Android Lint.)

  • 如何删除所有资源? (2认同)

小智 9

在Android Studio中,有一个可用的快捷方式.

Ctlr + Alt + Shift + i(或Mac上的Cmd + Alt + Shift + i)

这将打开一个对话框,您可以在其中键入"未使用"以查看许多选项.

我通常输入"未使用的资源"并获得包括布局,字符串,绘图等的列表.


Ern*_*ega 6

改进@Ramesh R 答案,最好的方法是右键单击您的 res文件夹,选择Refactor删除未使用的资源

这个工具太棒了,我为他的开发者 xD 鼓掌;


Ram*_*h R 5

在Android Studio 2.0及更高版本中

在菜单中选择Refactor - >单击Remove Unused Resources ...


Bud*_*ril 1

你可以使用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.
Run Code Online (Sandbox Code Playgroud)