46

My project has a large number of String and ImageResources, many of which i feel are unused. Is there any way i can find out which of these resources are currently not been referenced from my code?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
user1730789
  • 5,157
  • 8
  • 36
  • 57

9 Answers9

100

In Android Studio (tried up to Version 2.1.3), you can simply go to Main Menu -> Analyze -> Run Inspection by Name..., and select Unused resources

enter image description here

(It runs Android Lint for you.)

TechAurelian
  • 5,561
  • 5
  • 50
  • 65
21

In Android Studio there is a shortcut available.

Press Ctlr + Alt + Shift + i (or Cmd + Option + Shift + i on Mac)

This will open a dialog in which you can type "Unused" to see a number of options.

I generally type "unused resources" and get a list including layouts, strings, drawables, etc.

Morgan Koh
  • 2,297
  • 24
  • 24
Shrini Jaiswal
  • 1,090
  • 12
  • 12
9

In Android Studio 2.0 and above

in menu select Refactor-->click on Remove Unused Resources...

Ramesh R
  • 7,009
  • 4
  • 25
  • 38
6

Improving @Ramesh R answer, the best way is Right click on your res folder, Select Refactor and Remove Unused Resources.

This tool is fantastic, my applauses to his developer xD;

Ernesto Vega
  • 470
  • 6
  • 12
1

you can use 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.
Buda Gavril
  • 21,409
  • 40
  • 127
  • 196
1

Yes, the ADT in eclipse includes android lint

Refer android lint

Linga
  • 10,379
  • 10
  • 52
  • 104
1

You can use this library
Place it to project folder and run jar from command line.

jimpanzer
  • 3,470
  • 4
  • 44
  • 84
Viacheslav
  • 5,443
  • 1
  • 29
  • 36
  • This jar program finds resources that lint overlooks, such as in colors, dimensions etc... – Guy Jan 09 '14 at 10:27
1

If you want to delete unused resources in drawable file : Click on drawable file ~ then Click Refactor ~ then Click Remove Unused Resources..

0

Regarding the image resources you would like to remove, you should also consider moving all the drawable-xxxx folders out of your project into a temporary folder, then do a rebuild all, and take a look at the build message list which will tell you which ones are missing.

This can be specially useful if you want to get an overview of which resources you are effectively using and maybe replace them with an icon font or svg resources, possibly with the help of the Android Iconics library.

Daniel F
  • 13,684
  • 11
  • 87
  • 116