Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically removing unreferenced strings from strings.xml

In my Android app I have a lot of strings in strings.xml that never get used because I removed the code modules that referenced them. Is there an automatic way in Eclipse or using some other tool that will remove those strings?

like image 992
Johann Avatar asked Jul 22 '13 07:07

Johann


People also ask

What is a string in XML?

Definition of String in XML. XML Schema defines in a way what an XML document contains, therefore, XSD defines the string so, it can be defined as a value that contains character strings also has Unicode character given by XML and represented using the type xs: string, while this type has a white space character and maintained by ...

What is the use of clean strings XML file?

Clean strings.xml file helps to easily maintain and translate strings to different languages — screen after screen. If you want you can create strings.xml file per screen — settings-strings.xml, profile-strings.xml.

Can StackOverflow help remove non-utf8 characters from XML files?

Unfortunately, StackOverflow was unable to help my for that, since I only found questions (and answers) related to stripping/removing non-UTF8 characters: close, yet still not enough for what I need, since there are a lot of legitimate UTF8 characters that might cause issues within a XML file.

How to initialize string in XML?

How to Initialize String in XML? A string is initialized in the Element name with the type ‘string’. For example: It returns the string in the element name, if it is an integer then it returns a value. If the type doesn’t have any content then it could be declared as a string, not as any data types.


2 Answers

for i in $(lint . | grep 'The resource R.string.* appears to be unused' | perl -ne 'print "$1\n" if /R.string.(.*) appears/'); do  perl -pi -e 's/.*<string name="'$i'".*\n//' res/values*/strings.xml; done
like image 175
Guillaume Cottenceau Avatar answered Nov 09 '22 00:11

Guillaume Cottenceau


Android Lint can do it for you. Try: Right clic on your project > Android Tools > Run Lint: Check for Common Errors. Depending on your Lint settings, the unused strings will be shown.

like image 33
Brtle Avatar answered Nov 09 '22 01:11

Brtle