我想删除所有未使用的布局,字符串,绘图,颜色等从我的Android res目录。是否有任何工具可以给我一个文件列表,我可以从我的存储库中删除特定文件中的元素(例如未使用的字符串条目),这些文件不再使用?
当前回答
也许有用 Andround Unused Resources是一个Java应用程序,它会扫描你的项目中未使用的资源。未使用的资源会不必要地占用空间,增加构建时间,并使IDE的自动完成列表变得混乱。
要使用它,确保你的工作目录是你的Android项目的根目录,并运行:
java -jar AndroidUnusedResources.jar
https://code.google.com/p/android-unused-resources/
其他回答
自从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),手机将无法连接到手表。我花了好几个小时才找出应用程序中的这个漏洞。
1 - - - >
Android Studio菜单> Refactor >删除未使用的资源
如下图:
**
OR
**
2——>第二种方式
->按Ctrl Alt Shift i,在Windows中输入“unused resources”(不带引号)
->使用⌘Option Shift i for mac
or
-> cmd + Alt + Shift for mac
我们开源了一个工具,可以根据lint输出删除android项目中所有未使用的资源。 可以在这里找到:https://github.com/KeepSafe/android-resource-remover
推荐文章
- apk (.apk)和应用程序包(.aab)的区别
- 如何设置超时在改造库?
- Android - SPAN_EXCLUSIVE_EXCLUSIVE跨度不能为零长度
- TextView的字体大小在Android应用程序改变字体大小从本机设置
- 如何模拟Android杀死我的进程
- 禁用EditText闪烁光标
- Android Eclipse -无法找到*.apk
- 设置TextView文本从html格式的字符串资源在XML
- 如何允许所有网络连接类型HTTP和HTTPS在Android(9)馅饼?
- Android加载JS包失败
- Android Studio, logcat在应用程序关闭后清理
- 在android中从上下文获取活动
- 无法解析主机"<URL here>"没有与主机名关联的地址
- getActivity()在Fragment函数中返回null
- 按钮背景是透明的