War*_*ith 31
我写了一个基于python的工具来解决这个问题.由于这不是直接共享它的地方,我创建了一个现在离线的项目页面.
更新:
开发已经停止,因为Lint可以做同样的事情并且已经包含在Android SDK中.
Cri*_*ian 17
我只是为了好玩而写了这个bash脚本:
PROJECT="/path/to/the/project"
for file in $(ls $PROJECT/res/drawable -l | awk '{ print $8}' | sed 's/\..\+//g'); do count=0; for SRCFILE in `find $PROJECT -name "*.xml" -print 2> /dev/null`; do let "count+=$(grep -c @drawable/$file $SRCFILE)"; done; for SRCFILE in `find $PROJECT -name "*.java" -print 2> /dev/null`; do let "count+=$(grep -c R.drawable.$file $SRCFILE)"; done; if [ $count -lt 1 ]; then echo -e "\e[0;31m$file\e[0m not used"; else echo -e "\e[0;32m$file\e[0m used"; fi; done;
Run Code Online (Sandbox Code Playgroud)
它工作正常,虽然我是一个bash新手,所以它可以大大改善:

它仅搜索drawables资源(@drawable/name在XML文件和R.drawable.nameJava文件上).
顺便说一句,我不知道,boxscore并calendarlogos没有在我的项目中使用.另一个有趣的事实是大多数用户不使用Linux,所以这对太多人来说无济于事.
对于MacO会是这样的:
PROJECT="/path/to/the/project"
for file in $(ls -l $PROJECT/res/drawable | awk '{ print $9}' | sed 's/\..\+//g'); do count=0; for SRCFILE in `find $PROJECT -name "*.xml" -print 2> /dev/null`; do let "count+=$(grep -c @drawable/$file $SRCFILE)"; done; for SRCFILE in `find $PROJECT -name "*.java" -print 2> /dev/null`; do let "count+=$(grep -c R.drawable.$file $SRCFILE)"; done; if [ $count -lt 1 ]; then echo -e "$file not used"; else echo -e "$file used"; fi; done;
Run Code Online (Sandbox Code Playgroud)
And*_*yeu 10
请检查:http: //code.google.com/p/android-unused-resources
更新14.12.2011:现在您可以找到尽可能简单的未使用资源.更新到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)
| 归档时间: |
|
| 查看次数: |
9558 次 |
| 最近记录: |