我想删除所有未使用的布局,字符串,绘图,颜色等从我的Android res目录。是否有任何工具可以给我一个文件列表,我可以从我的存储库中删除特定文件中的元素(例如未使用的字符串条目),这些文件不再使用?
当前回答
检查string.xml。
这很简单(至少在我的Eclipse版本中)
在Eclipse for Android(我有版本v22.6.2-1085508)
在“包资源管理器”中左键单击项目名称 选择“Android Tools”。 选择“运行Lint:检查常见错误”。
现在当打开strings.xml时,您将看到未使用的字符串被高亮显示。
您可以修复其他潜在的问题。
其他回答
自从ADT 16以来,你可以使用Android Lint。这真是个神奇的工具。
Android Lint is a new tool for ADT 16 (and Tools 16) which scans Android project sources for potential bugs. 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.
然而,它有一些问题(不知道它们是否已经修复),如果你想删除数百个据称未使用的资源,我建议在资源删除期间手动编译项目几次,以确保Lint没有删除所需的东西。
在Android Studio中,
Analyze ->按名称执行巡检
(Mac的快捷方式shift+command+option+i, Windows/Linux的Ctrl + shift+ A)。
并输入'unused resources'。
这样你就可以删除未使用的资源、变量、符号、本地化、库等。
在列表中选择巡检项,选择巡检范围->OK
如果你在使用多种香料时要小心。根据你所选择的口味,棉绒可能会给出虚假的未使用的资源。
Android Wear开发者注意:“Remove Unused Resources”将删除你声明能力名称的xml文件(res/values/ Wear .xml),手机将无法连接到手表。我花了好几个小时才找出应用程序中的这个漏洞。
在Android Studio中运行Lint并找到所有未使用的资源后,您可以从Inspection选项卡中单击其中一个。它提供了关于该问题的一些详细信息以及修复该问题的一些选项。其中之一是删除所有未使用的资源。选择该选项将删除所有未使用的资源。
推荐文章
- 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
- 安装APK时出现错误
- 碎片中的onCreateOptionsMenu
- TextView粗体通过XML文件?
- 如何使线性布局的孩子之间的空间?
- DSL元素android.dataBinding。enabled'已过时,已被'android.buildFeatures.dataBinding'取代
- ConstraintLayout:以编程方式更改约束
- PANIC: AVD系统路径损坏。检查ANDROID_SDK_ROOT值
- 如何生成字符串类型的buildConfigField
- Recyclerview不调用onCreateViewHolder
- Android API 21工具栏填充
- Android L中不支持操作栏导航模式
- 如何在TextView中添加一个子弹符号?
- PreferenceManager getDefaultSharedPreferences在Android Q中已弃用
- 在Android Studio中创建aar文件