代码分析工具FindBugs在Android开发中的应用

2016-09-14  本文已影响156人  sylcrq

参考资料:
Static Code Analysis using FindBugs (Android Studio)
How to improve quality and syntax of your Android code

1. 在Android Studio中使用

2. 在Gradle中使用

在工程的build.gradle中添加FindBugs的task:

apply plugin: 'findbugs'
 
task findbugs(type: FindBugs) {
    ignoreFailures = false
    effort = "default"
    reportLevel = "medium"
    excludeFilter = new File("${project.rootDir}/findbugs/findbugs-filter.xml")
    classes = files("${project.rootDir}/app/build/intermediates/classes")
    source = fileTree('src/main/java/')
    classpath = files()
    reports {
        xml.enabled = true
        html.enabled = true
        xml {
            destination "$project.buildDir/findbugs/findbugs-output.xml"
        }
        html {
            destination "$project.buildDir/findbugs/findbugs-output.html"
        }
    }
}

需要注意reports中的xml.enabledhtml.enabled只能enable一个,否则运行时会报如下错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:findbugs'.
> FindBugs tasks can only have one report enabled, however more than one report was enabled. You need to disable all but one of them.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
上一篇下一篇

猜你喜欢

热点阅读