Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FindBugs Android Gradle No classes configured error

I am trying to use the FindBugs plugin for Gradle with an Android build.

The build.gradle file

buildscript {
  repositories {
    mavenCentral()        
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:0.6.+'
  }
}
apply plugin: 'android'
apply plugin: 'findbugs'

android {
  compileSdkVersion 19
  buildToolsVersion "19.0.0"
  defaultConfig {
    minSdkVersion 8
    targetSdkVersion 19        
  }
}

dependencies {
  compile 'com.android.support:appcompat-v7:+'
}

But when I execute the check task it says

No classes configured for FindBugs analysis.

How do I configure classes for FindBugs analysis?

like image 851
Milina Udara Avatar asked Dec 11 '13 08:12

Milina Udara


3 Answers

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"
        }
    }
}
like image 167
Patrick Henderson Avatar answered Sep 28 '22 04:09

Patrick Henderson


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

like image 35
Xavier Ducrohet Avatar answered Sep 28 '22 04:09

Xavier Ducrohet


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.

like image 25
Markymark Avatar answered Sep 28 '22 02:09

Markymark