清理未使用的 Android 权限 [英] Clean up unused Android permissions

查看:48
本文介绍了清理未使用的 Android 权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想研究 [在 Mainfest.xml 中请求] 权限在 Android 应用程序中的使用方式和位置以删除它们,是否有一种简单的方法可以做到这一点?lint 或 findbugs 是否为跟踪项目中使用/滥用的权限提供某种支持?

If I wanted to research how and where permissions [requested in the Mainfest.xml] were used in an Android app for the purposes of removing them is there an easy way of doing this? Does lint or findbugs offer some sort of support for tracking permissions used/abused in a project?

推荐答案

我从未来来到拯救你的生命.

I came from the future to save your lives.

在这里(将来),LINT 会检查缺少的权限,正如您在 LINT 检查中看到的那样.

Here (in the future), LINT does check for missing permissions as you can see on LINT checks.

  • 因此,转到您的 AndroidManifest.xml 并删除所有标签 使用 Android 权限(意思是,不要t 删除属于您的应用的权限,例如 UA_DATAC2D_MESSAGE).
  • 然后运行 ​​LINT 分析.点击Analyze然后Inspect Code...
  • 查看Android ->常量和资源类型不匹配
  • 您应该会看到所有缺失的权限.
  • 然后您只需右键单击它们并选择Apply fix "Add Permission".如果您选择此选项,Android Studio 将为每个错误包含一个权限.因此,您最终会在 Manifest 文件上获得多个相同权限的副本,只需删除重复项即可.您也可以手动完成.
  • So, go to your AndroidManifest.xml and remove all tags <uses-permission> using Android permissions (meaning, don't delete permissions that belong to your app, such as UA_DATA and C2D_MESSAGE).
  • Then run LINT analysis. Click on Analyze then Inspect Code...
  • Look under Android -> Constant and Resource Type Mismatches
  • You should see all missing permissions.
  • Then you can just right-click them and select Apply fix "Add Permission". If you select this option, Android Studio will include one permission for every error. So you'll end up with multiple copies of the same permission on your Manifest file, just delete the duplicates. You can do it manually too.

这里是 LINT 规则的描述:

Here is the description of the LINT rule:

ID 资源类型

说明

此检查会查看已使用各种支持注释(例如 RequiresPermission 或 UiThread)进行注释的 Android API 调用,并标记未按照注释指定正确使用 API 的任何调用.此检查标记的错误示例:

This inspection looks at Android API calls that have been annotated with various support annotations (such as RequiresPermission or UiThread) and flags any calls that are not using the API correctly as specified by the annotations. Examples of errors flagged by this inspection:

  • 将错误类型的资源整数(例如 R.string)传递给需要不同类型的 API(例如 R.dimen).
  • 忘记在需要它的方法中调用被覆盖的方法(通过 super)
  • 在未在清单中声明权限的情况下调用需要权限的方法
  • 将资源颜色引用传递给需要 RGB 整数值的方法.

...还有更多.有关更多信息,请参阅 http://developer.android.com/tools/debugging 中的文档/annotations.html

...and many more. For more information, see the documentation at http://developer.android.com/tools/debugging/annotations.html

<小时>

我使用的是 Android Studio 2.1.2.


I'm using Android Studio 2.1.2.

这篇关于清理未使用的 Android 权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆