Android Studio 配置 FindBugs

来源:互联网 发布:酷家乐装修设计软件 编辑:程序博客网 时间:2024/05/29 16:54

简介

FindBugs 静态分析工具,检查类或者jar文件,将字节码与一组缺陷模式进行对比发现可能的问题。

bug 分为三个级别:low,medium,high。

bug种类:

  • Bad practice 坏的实践
  • Correctness 一般的正确性问题
  • Internationalization 国际化
  • Performance 性能问题
  • Dodgy 危险的
  • Malicious code vulnerability 可能受到的恶意攻击
  • Multithreaded correctness 多线程的正确性

使用方法

1、 Android Studio 中的setting-plugins里搜findbugs 选择 FindBugs-IDEA,安装这个插件。

2、装好之后在setting-other setting-findbugs-plugins里面勾选 for android 插件(Windows是在plugin中添加一个for android插件)和Reporting里面的High级别(先处理High级别的bug)。

3、最后在Filter中的Exclude filter files中添加findbugs-filter.xml文件。文件路径可根据自己去选择。

4、配置完之后,在Android Studio 下方的会有一个findbugs 工具栏,点击findbugs 工具栏,左侧会有一些检查方式:current file、changlist files 等等,点击就会有相应的检查操作了。

findbugs-filter.xml

<?xml version="1.0" encoding="UTF-8"?><FindBugsFilter>    <!-- http://stackoverflow.com/questions/7568579/eclipsefindbugs-exclude-filter-files-doesnt-work -->    <Match>        <Class name="~.*\.R\$.*" />    </Match>    <Match>        <Class name="~.*\.Manifest\$.*" />    </Match>    <!-- All bugs in test classes, except for JUnit-specific bugs -->    <Match>        <Class name="~.*\.*Test" />        <Not>            <Bug code="IJU" />        </Not>    </Match>    <Match>        <Package name="~com\.ali\.android\.app\.lib.*" />    </Match>    <Match>        <Package name="~com\.asmack.*" />    </Match>    <Match>        <Package name="~com\.alipay\.euler\.andfix.*" />    </Match>    <Match>        <Package name="~com\.handmark\.pulltorefresh.*" />    </Match></FindBugsFilter>