Answers:
在Android Studio上:
菜单 -> 分析 -> 按名称运行检查 -> 未使用的资源
选中文件掩码复选框,然后将其放在strings.xml文本字段中。
tools:ignore="UnusedResources"
使用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.
Warning: The resource R.string.... appears to be unused [UnusedResources] [lint] <string name="...">some text</string>
要检查string.xml。
这很容易(至少在我的Eclipse版本中)
在Eclipse for Android中(我具有v22.6.2-1085508版本)
现在,当您打开strings.xml时,您将看到未使用的字符串突出显示。
您可以解决其他潜在问题。
这就是我使用Android 3.3的方式。
检入对存储库的所有未保存的更改。
注意:尝试构建项目。如果编译失败,则很有可能是从某些未使用的layout / menu xmls中引用了这些strings.xml。因此,这些布局xml也可以手动删除!
构建并运行。测试!
从项目的根目录运行此脚本。
查找`res / values / *。xml`中的资源文件;做
用于`grep'。* / \ 1 / g'`中的字符串名; 做
count1 =`grep -rc“ R.string。$ {stringname}” src | egrep -v':0 $'| wc -l`
count2 =`grep -rc“ @string / $ {stringname}” res /布局| egrep -v':0 $'| wc -l`
count3 =`grep -rc“ @string / $ {stringname}” res /菜单| egrep -v':0 $'| wc -l`
count4 =`grep -rc“ @string / $ {stringname}” AndroidManifest.xml | egrep -v'^ 0 $'| wc -l`
count5 =`grep -rc“ @string / $ {stringname}” res / xml | egrep -v':0 $'| wc -l`
if [$ count1 -eq 0 -a $ count2 -eq 0 -a $ count3 -eq 0 -a $ count4 -eq 0 -a $ count5 -eq 0]; 然后
echo $ resourcefile:$ stringname
科幻
做完了
做完了
在`find res / drawable * -type f -name'*。???'中的资源名称; 做
resource =`echo $ resourcename | xargs基本名称| sed“ s / ^ \(。* \)\ .... $ / \ 1 / g”`
count1 =`grep -rc“ R \ .drawable \。$ {resource}” src | egrep -v':0 $'| wc -l`
count2 =`grep -rc“ @drawable / $ {resource}” res /布局| egrep -v':0 $'| wc -l`
count3 =`grep -rc“ @drawable / $ {resource}” res / drawable * / *。xml | egrep -v':0 $'| wc -l`
count4 =`grep -rc“ @drawable / $ {resource}” res /菜单| egrep -v':0 $'| wc -l`
count5 =`grep -rc“ @drawable / $ {resource}” AndroidManifest.xml | egrep -v'^ 0 $'| wc -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`中获取资源名称;做
resource =`echo $ resourcename | xargs基本名称| sed“ s / ^ \(。* \)\ .... $ / \ 1 / g”`
count1 =`grep -rc“ R \ .layout \。$ {resource}” src | egrep -v':0 $'| wc -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 ...
Custom scope,选择Production classes->app->values以查找未使用的字符串,颜色...