Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any simple way to find out unused strings in Android project?

Tags:

android

People also ask

How do I find unused strings in Android?

In Android Studio there is a shortcut available. 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.

What is the location of the strings xml file in the Android project?

Normally you can find string. xml in res->values folder path.

What are strings in Android?

A single string that can be referenced from the application or from other resource files (such as an XML layout). Note: A string is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file).


On Android Studio:

Menu -> Analyze -> Run Inspection by Name -> Unused resources

Check File mask(s) checkbox and put strings.xml in the text field.


Here is another solution that is fairly easy. In the Android Studio menu go to

Refactor > Remove Unused Resources....

enter image description here

Click Preview to see what the unused resources are and selectively remove them.


In my case "Run Inspection by Name" didnt work, despite the fact I was using "Remove unused resources".

Solution:

  1. Open strings.xml
  2. Secondary click
  3. Refactor --> Remove Unused Resources

I have no clue why "Remove Unused Resources" works one way but not the other.


With ADT 16 you can do it as simple as possible. Update to ADT 16 and use Android Lint. It is really amazing tool. It can find all unused resources (not only strings) and many more. From its official site:

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.