I've found an unused string resource, like:
<string name="obsoletestring">my name is null!</string>
However it is in tens of files, of different languages, in different strings.xml
files in values
, values-af
, values-be
, etc folders.
I must have missed something not to know any way to do this in Android Studio other than modifying it by hand one by one.
How to delete an unused string resource for all configurations? 如何为所有配置删除未使用的字符串资源?
To identify all unused resources:
There is no really easy way in Android Studio (v 1.0) to remove a resource string for all locales. However, you can search and replace in files. Fortunately, the translation files use only a single line in most cases so this works pretty well.
In Android Studio:
.*name="obsoletestring".*\\n
It is now possible inside Android Studio. After Lint checks you see an option on the right Remove All Unused Resources !
To Delete a single string resource across all locale files, you can use the "Translation Editor". 1. Right click on the res directory to open the translation editor. 2. Select "Show All Keys" selector, and choose "Filter by Text". Supply the name of the resource that you want to delete. 3. Select the resource, and click on the "-" button
在IDE支持出现之前,这些内容将起作用:
find -name strings.xml|xargs -rd\\n sed -ri '/"string_to_delete"/d'
In Android Studio 2.3 it's possible to remove all unused resources.
Refactor -> Remove Unused Resources...
From the results select all string resources that are unused.
Menu -> Find -> Replace in Path
事实上,Android Lint应报告未使用的资源,但您也可以尝试使用这个漂亮的插件。
Beware that the REMOVE UNUSED RESOURCES command cannot recognize a programmatically accessed resource as a used resource (such as getIdentifier(..) etc.). So, if you do access resources that way, it is highly risky to use that command!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.