我有一个巨大的Android项目,其中声明了许多字符串strings.xml
.我想删除未使用的字符串strings.xml
.
有没有简单的方法呢?
Ode*_*ner 221
在Android Studio上:
菜单 - > 分析 - > 按名称运行检查 - > 未使用的资源
选中File mask(s)复选框并strings.xml
输入文本字段.
cut*_*iko 26
在我的情况下,"按名称运行检查"没有工作,尽管事实上我正在使用"删除未使用的资源".
解:
我不知道为什么"删除未使用的资源"以一种方式工作而不是另一种工作方式.
Sur*_*gch 26
这是另一种相当容易的解决方案.在Android Studio菜单中转到
重构>删除未使用的资源....
单击" 预览"以查看未使用的资源,并有选择地删除它们.
And*_*yeu 22
使用ADT 16,您可以尽可能简单地完成.更新到ADT 16并使用Android Lint.这真是太神奇了.它可以找到所有未使用的资源(不仅仅是字符串)等等.从其官方网站:
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)
这就是我在 Android 3.3 上的做法。
将任何未保存的更改签入您的存储库。
注意:尝试构建项目。如果编译失败,很可能这些 strings.xml 是从一些布局/菜单 xmls 引用的,这些布局/菜单 xmls 本身未使用。所以那些布局xmls也可以手动删除!
构建并运行。测试!
Car*_*uin -1
从项目的根目录运行此脚本。
对于“find res/values/*.xml”中的资源文件;做 对于 `grep '.*/\1/g'` 中的字符串名称;做 count1=`grep -rc "R.string.${stringname}" src | egrep -v ':0$' | 厕所-l` count2=`grep -rc "@string/${stringname}" res/layout | count2=`grep -rc "@string/${stringname}" res/layout | egrep -v ':0$' | 厕所-l` count3=`grep -rc "@string/${stringname}" res/menu | count3=`grep -rc "@string/${stringname}" res/menu | egrep -v ':0$' | 厕所-l` count4=`grep -rc "@string/${stringname}" AndroidManifest.xml | egrep -v '^0$' | 厕所-l` count5=`grep -rc "@string/${stringname}" res/xml | count5=`grep -rc "@string/${stringname}" res/xml | egrep -v ':0$' | 厕所-l` 如果 [ $count1 -eq 0 -a $count2 -eq 0 -a $count3 -eq 0 -a $count4 -eq 0 -a $count5 -eq 0 ]; 然后 echo $资源文件:$字符串名称 菲 完毕 完毕 对于 `find res/drawable* -type f -name '*.???'` 中的资源名称;做 资源=`echo $资源名称| xargs 基本名称 | sed "s/^\(.*\)\....$/\1/g"` count1=`grep -rc "R\.drawable\.${资源}" src | egrep -v ':0$' | 厕所-l` count2=`grep -rc "@drawable/${resource}" res/layout | count2=`grep -rc "@drawable/${resource}" res/layout | egrep -v ':0$' | 厕所-l` count3=`grep -rc "@drawable/${resource}" res/drawable*/*.xml | egrep -v ':0$' | 厕所-l` count4=`grep -rc "@drawable/${resource}" res/menu | count4=`grep -rc "@drawable/${resource}" res/menu | egrep -v ':0$' | 厕所-l` count5=`grep -rc "@drawable/${resource}" AndroidManifest.xml | egrep -v '^0$' | 厕所-l` 如果 [ $count1 -eq 0 -a $count2 -eq 0 -a $count3 -eq 0 -a $count4 -eq 0 -a $count5 -eq 0 ]; 然后 echo $资源名 菲 完毕 对于“find res/layout/*.xml”中的资源名称;做 资源=`echo $资源名称| xargs 基本名称 | sed "s/^\(.*\)\....$/\1/g"` count1=`grep -rc "R\.layout\.${资源}" src | egrep -v ':0$' | 厕所-l` 如果 [ $count1 -eq 0 ]; 然后 echo $资源名 菲 完毕
它给了我这样的输出:
res/values/activity_strings.xml:activity_more res/values/activity_strings.xml :activity_as_reply_to res/values/db_strings.xml : sql_backlog_count res/values/db_strings.xml : sql_backlog_update_last_resend ...
归档时间: |
|
查看次数: |
28405 次 |
最近记录: |