FindBugs Android Gradle No classes configured error

In newer versions of Android Studio this problem could be attributed to the fact that the location of the classes directory has changed.

The new location (as of 0.8.2) is:

build/intermediates/classes/{build_variant_name}/

for example

build/intermediates/classes/debug/
task findbugs(type: FindBugs) {
    excludeFilter = file('config/findbugs/findbugs.xml')
    ignoreFailures = true
    classes = fileTree('build/intermediates/classes/preproduction/')
    source = fileTree('src/main/java/')
    classpath = files()
    effort = 'max'
    reports {
        xml {
            destination "reports/findbugs.xml"
        }
    }
}

This is not possible at the moment as findbugs expect Gradle's normal Java SourceSets but the android plugin uses custom ones.

There's work planned in both Gradle and in the Android plugin to allow using the default SourceSets which will enable FindBugs.

You track this issue here: https://code.google.com/p/android/issues/detail?id=55839


I was able to solving the problem

by adding find bug as separate task

 task findbugs(type: FindBugs) {
    ignoreFailures = true
    classes = fileTree('build/classes/debug/')
    source = fileTree('src/main/java/')
    classpath = files()
   effort = 'max'
 }

this task can run using

gradle findbugs

If you are using android-test plugin you have to exclude findbugsTestDebug task when build.

gradle build -x  findbugsTestDebug

This is definitely possible. At least now. The answer can be seen on https://gist.github.com/rciovati/8461832 at the bottom.

apply plugin: 'findbugs'

// android configuration

findbugs {
    sourceSets = []
    ignoreFailures = true
}

task findbugs(type: FindBugs, dependsOn: assembleDebug) {

    description 'Run findbugs'
    group 'verification'

    classes = fileTree('build/intermediates/classes/debug/')
    source = fileTree('src/main/java')
    classpath = files()

    effort = 'max'

    excludeFilter = file("../config/findbugs/exclude.xml")

    reports {
        xml.enabled = true
        html.enabled = false
    }
}

check.doLast {
    project.tasks.getByName("findbugs").execute()
}

The important part here is dependsOn: assembleDebug. Without that you will get a No classes configured for FindBugs analysis error message.

Refer to this https://stackoverflow.com/a/7743935/1159930 for the exclude file.