spotbugs / spotbugs-gradle-plugin

https://plugins.gradle.org/plugin/com.github.spotbugs
Apache License 2.0
180 stars 68 forks source link

Running SpotBugs on and Android project using Gradle #426

Open baloghadamsoftware opened 3 years ago

baloghadamsoftware commented 3 years ago

Hello,

I am trying out SpotBugs on open-source projects. The actual goal is to test my modifications in the locally SpotBugs, but I am already stuck at running release SpotBugs.

I read several, sometimes contradiction documentations. I had various errors, none of the worked. Finally, I found this one: https://mikedemaso.com/tech/2020-06-10-spotbugs-gradle-plugin-android/

This is the only one that seemed to work, but it still does not work perfectly.

The project I am using for testing is an Android app, called microMathematics: https://github.com/mkulesh/microMathematics

I changed its build.gradle to the following three files:

gradle.zip

I also modified the Gradle version in gradle/wrapper/gradle-wrapper.properties to 5.6 because the SpotBugs Gradle plugin requires that version.

However, after the analysis I got the following error message:

Task :app:spotbugsDebug The following classes needed for analysis were missing: android.os.AsyncTask android.content.ContextWrapper android.os.Parcelable android.os.Parcelable$Creator android.view.View$OnLongClickListener android.view.View$OnFocusChangeListener android.widget.LinearLayout android.view.View$OnClickListener android.widget.TableLayout android.graphics.drawable.Drawable android.view.ScaleGestureDetector$OnScaleGestureListener android.widget.FrameLayout android.view.inputmethod.InputConnectionWrapper android.text.TextWatcher android.view.GestureDetector$SimpleOnGestureListener android.view.ActionMode$Callback android.app.Dialog android.widget.ArrayAdapter android.os.Handler android.widget.AdapterView$OnItemClickListener android.widget.BaseAdapter android.view.View android.widget.ImageView android.widget.EditText android.widget.TextView android.content.ComponentCallbacks android.view.View$OnCreateContextMenuListener android.widget.ImageButton android.view.ViewGroup android.app.Activity android.content.Context org.xmlpull.v1.XmlPullParser org.xmlpull.v1.XmlSerializer android.content.res.Resources android.widget.Toast android.os.Bundle android.widget.LinearLayout$LayoutParams android.view.LayoutInflater android.graphics.Paint android.widget.RadioButton android.widget.CheckBox android.net.Uri android.content.res.AssetManager android.text.Editable android.os.Parcel android.content.res.TypedArray android.graphics.Color android.util.Log android.graphics.Paint$Style android.graphics.PathEffect android.graphics.DashPathEffect android.graphics.Typeface android.graphics.BitmapFactory android.graphics.Canvas android.content.pm.PackageInfo android.content.pm.ApplicationInfo android.graphics.Bitmap$Config android.graphics.Bitmap android.graphics.Bitmap$CompressFormat android.content.pm.PackageManager android.content.pm.PackageManager$NameNotFoundException android.graphics.Point android.content.ContentResolver android.net.Uri$Builder android.provider.DocumentsContract android.database.Cursor android.content.SharedPreferences android.content.SharedPreferences$Editor android.graphics.Path android.graphics.Rect android.util.DisplayMetrics android.view.ContextMenu android.widget.AdapterView$AdapterContextMenuInfo android.text.format.DateFormat android.view.MenuItem android.os.Message android.text.TextPaint android.widget.RelativeLayout$LayoutParams android.os.Environment android.widget.ListView android.widget.Button android.graphics.RectF android.graphics.Shader android.graphics.Shader$TileMode android.view.View$MeasureSpec android.graphics.LinearGradient android.view.ViewParent android.view.MotionEvent android.view.ContextMenu$ContextMenuInfo android.util.Xml android.graphics.Matrix android.graphics.SweepGradient android.view.MenuInflater android.view.Menu android.os.IBinder android.view.inputmethod.InputMethodManager android.view.ActionMode android.graphics.Paint$Cap android.graphics.Paint$Join android.graphics.Path$Op android.graphics.PorterDuff$Mode android.graphics.Xfermode android.graphics.ColorMatrix android.graphics.Path$FillType android.graphics.PorterDuffXfermode android.graphics.ColorMatrixColorFilter android.graphics.PathMeasure android.util.Base64 android.graphics.RadialGradient android.widget.TextView$BufferType android.view.Gravity android.view.ScaleGestureDetector android.widget.EdgeEffect android.webkit.MimeTypeMap android.text.TextUtils android.view.KeyEvent android.content.res.Configuration android.os.LocaleList android.widget.Scroller android.view.FocusFinder android.view.animation.AnimationUtils android.graphics.Canvas$VertexMode android.content.ClipData$Item android.content.ClipData android.content.ClipboardManager android.content.res.AssetFileDescriptor android.content.Intent android.graphics.Picture android.content.res.Resources$Theme android.graphics.drawable.PictureDrawable android.widget.RadioGroup android.graphics.PorterDuffColorFilter android.system.Os android.os.Build android.view.Window android.view.SubMenu android.view.ViewGroup$LayoutParams android.util.TypedValue android.widget.ProgressBar android.widget.TableLayout$LayoutParams android.widget.TableRow android.view.WindowManager$LayoutParams android.widget.AdapterView android.widget.ListAdapter android.os.Build$VERSION android.graphics.PixelFormat android.util.AttributeSet android.os.Build$VERSION_CODES android.view.ViewGroup$MarginLayoutParams android.view.GestureDetector android.graphics.PorterDuff android.R$attr android.R$color android.R android.R$id android.provider.OpenableColumns android.widget.RelativeLayout android.provider.DocumentsContract$Document android.Manifest$permission android.Manifest android.text.InputType

Task :app:spotbugsDebug FAILED

FAILURE: Build failed with an exception.

If I use the --stacktrace option, I get the following excpeption at the end:

I also tried to use newer Gradle, but then I got another kind of strange error. After that I also tried to use newer Gradle Android plugin and then this same error came back.

What I find strange is that not all, but almost all android classes are missing. Some of them are not. I grepped for all the imports and extracted a list of the used Android classes (without inner classes). I compared them to the list of missing classes and there were some differences.

imported_and_missing.zip

What did I wrong? How to analyze this project without errors? Also, how to use the locally built spotbugs instead of the one from the repository?

The Java version I use is OpenJDK 11.

On another project (https://github.com/matsim-org/matsim-libs), which uses Maven I already successfully tested my local SpotBugs instance. All I want to is to do the same on this Gradle-based project.

The third project I intend to analyze using the locally built SpotBugs is SpotBugs itself. Is there an already existing config for that?

Thank you for your help in advance!

welcome[bot] commented 3 years ago

Thanks for opening your first issue here! :smiley: Please check our contributing guideline. Especially when you report a problem, make sure you share a Minimal, Complete, and Verifiable example to reproduce it in this issue.

KengoTODA commented 3 years ago

refs #90