-
-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to use Spotbugs in Android application #90
Comments
Thanks for opening your first issue here! 😃 |
@ZOlbrys please define |
@KengoTODA Thanks for the response. I've added this, and now encounter a new error:
It looks like it's unable to find the sources/code for most of the android related classes. |
Thanks for your report, I also reproduced this problem in my local. Then maybe we are facing something unknown, I'll wait contribution from gradle/android experts... |
I experienced the same issue today. I'm not sure if it's a problem with spotbugs or something else, because the actual task that is failing for both @ZOlbrys and me is |
Upon further inspection, the
Those tasks all fail because
|
Adding the following task to my gradle file allowed spotbugs to run correctly:
|
@AEFeinstein interesting - I'm still not getting this to work! I added that to my test project, but now I get this error:
Is my gradle file setup incorrectly? I wasn't able to find exact documentation on this stuff. |
@ZOlbrys I can't debug your particular problem, but here's my project with the plugin working |
@AEFeinstein Thanks for reaching out! I saw the files your gradle files and setup mine in a similar manner. I still see the same error though - so no progress, maybe. @KengoTODA any thoughts on the issue above? #90 (comment) |
No idea, I'm not Android guy... |
@ZOlbrys what happens when you run |
@KengoTODA understood - thanks for the support so far though! Appreciate it :) @AEFeinstein good news! I upgraded to Android Studio 3.3, and then ran the commands and that seems to have fixed my problem. I think the Android Studio update helped more than anything else - I see you were using a newer version of gradle as well... Anyways, I am able to run the tool now and verified that bugs are being reported. Thanks for the assistance! |
note @AEFeinstein has it wrong.. missing stuff wrap it the same way you flavors with buildtypes and one needs to add variant.javaCompiler files to classpath for other project modules my first run I just did it with the buildType of variant and got it to run correctly also note do a first run so that you know what to set the filter file to as you want to exclude the all the android lib stuff and your 3rd party libs However, I can confirm its working which is nice cause I still have problems attempting to use errorprone with kotlin right now..so its life saver if anyone wants to take a look, the project I am putting it into with the https://gitlab.com/fred.grott/droikotlinkit also note my solution points to the kotlin java classes correctly so I hope it helps those who are still stuck with it not working.. just call me Android Gradle-Plugin expert :) |
I would like to use spotbugs in our Android application, but creating a sourceSet and a javaCompile task for this seems so wrong. If the SpotBugsTask would have a setter for the We can directly call
that sourceDirs is not set. I actually don't understand the use for the sourceDir variable, because the setSourceSet also calls setSource . So in getAllSource the sources are added twice?
So if the SpotbugsTask either
or
we could easily get Spotbugs to work with Android. |
@MatFl I also came to the same conclusion: If there is no sourceSet set, the |
okay let me add a brief code ex its a multi module project with no app flavors project.extensions.extraProperties.set('SpotBugsTask', com.github.spotbugs.SpotBugsTask)
spotbugs {
toolVersion = '3.1.10'
ignoreFailures = false
excludeFilter = file("${rootDir}/config/findbugs-exclude-filter.xml")
// Search better
effort = 'max'
// Report all
reportLevel = 'low'
}
sourceSets {
// we define `main` sourceSet here, so SpotBugs Gradle Plugin generates `spotbugsMain` task
main {
java.srcDirs = ['src/main/java']
}
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
dependsOn 'assembleDebug'
group = "verification"
classes = fileTree("build/inteermediates/javac/debug/") + fileTree("build/tmp/kotlin-classes/debug/")
ignoreFailures = true
classpath = files()
// configure automatically generated tasks
reports {
xml.enabled = false
html.enabled = true
html {
destination file("$project.buildDir/outputs/reports/spotbugs/spotbugs-debug.html")
stylesheet resources.text.fromFile("$rootDir/config/fancy.xsl")
}
}
}
task compileJava(overwrite: true) {
dependsOn 'compileDebugJavaWithJavac'
group = "build"
} so that is the general setup and works fine, note you will get a xerces xml parse warning on the referenced android framework classes but that can be ignored as far as I know |
Defining a java sourceSet and compiling the java task is (in my opinion) nothing more than a dirty workaround. |
I agree with @MatFl . Before changing how |
@WonderCsabo which version was working with your project? In my understanding, this plugin already behaved so when our organization forked. |
Plugin Version 1.6.6 . It broke when changes added for |
Nice share! It'll help our investigation. |
Hi. I want to share my configuration of spotbugs for android project: https://gist.github.com/mik9/fdde79052fef7f03c4325734701a39d7 Latest working plugin version: 1.6.6. Maybe it helps. |
Starting with 1.6.9 I do get
which was fine on 1.6.6. Config:
|
Android Studio 3.4 All versions that are newer than 1.6.6 do not work. |
Sorry, no help only observations: Why is this so difficult? Why is there no graceful AND meaningful (by that I mean output any semi-layman could read and understand) output. I call this trouble shooting at the DNA level/cellular level instead of the component level. I was truly saddened when I read "good news! I upgraded to Android Studio 3.3, and then ran the commands and that seems to have fixed my problem.". Imo, sadly nothing has fundamentally change in this 'area' in 35+ years. And this is even sadder. :( |
Hello all, check #180 and help us to confirm that new plugin works with Android project. We'll release stable version right after SpotBugs 4.0.0 release. |
Hi, I tried to use the SpotBugs Gradle Plugin v4.0.2 (which is SpotBugs 4.0.0) in a single Android project and got some errors like below:
My
The reason I commented the
I don't know why but I can't set the |
@henrychoi7 Not only Let me confirm what is your expectation. Do you want to set the source directory to analyse? https://spotbugs-gradle-plugin.netlify.com/com/github/spotbugs/snom/spotbugstask.html#sourceDirs |
@KengoTODA Thank you!
Therefore, I can't set
I think the last error seems to be lack of report destination source ( |
Thanks for updating information! Their release note has no description about it, so I'm still not sure how we should fix this issue. One workaround, is that, apply the base plugin and create |
Oh, I didn't know that was a known issue and I'm not sure why they removed I solved the problem above by creating my own task. Thank you again! 😄 I'm not very professional about Android Gradle plugin but, there must be a way to solve this issue to be native support for Android.. |
@KengoTODA do you have example of how to "create SpotBugsTask"? We're running into this issue but not quite sure how to apply the workaround! Excuse the lack of gradle skillz. |
@KengoTODA : FYI, AndroidJavaCompile has been totally removed. You can pin the spotbugsTask against the JavaCompile task instead. Verified it w/ the Android tools folks. |
Looks like a pretty simple change: spotbugs-gradle-plugin/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsTaskFactory.java Line 73 in ed1cecf
|
I can do a PR but I don't see any dev readme on how to test/validate this plugin... |
I already have a PR up for it: #252 |
Nice...what's the hold up on getting the PR merged and released @KengoTODA ? Looks pretty straightforward... |
Would really love to see this available. Could you share eta on release? |
I can confirm that adding:
makes following error disappear:
But instead, I have:
|
And to fix last error:
This makes pass spotbugs for my Android project. |
Hey all,
I've recently tried to get Spotbugs working in a sample Android application and I haven't had any luck.
Here's a sample project showing my attempt: https://github.com/ZOlbrys/SpotbugsExample
When I try to run Spotbugs via gradle, I see this error:
Here's my build.gradle app file:
I am running into these bugs on Android Studio 3.2.1 and Android Studio 3.3 RC2. Am I doing something wrong here? Thanks!
The text was updated successfully, but these errors were encountered: