Mark M. | has entered the room |
Mark M. | turned on guest access |
Sep 26 | 8:45 AM |
Scott W. | has entered the room |
Scott W. |
Hello Mark
|
Mark M. |
hello, Scott!
|
Mark M. |
how can I help you today?
|
Scott W. |
I've got a lint question
|
Mark M. |
I try to clean my dryer trap at least once a week
|
Scott W. |
;)
|
Scott W. |
my coffee is ready. brb
|
Scott W. |
ok
|
Sep 26 | 8:50 AM |
Scott W. |
In Android Studio, you can click on Analyze and then Inspect Code and it'll give all these great warnings
|
Scott W. |
they are split into categories: Android, General, Java, XML, ...
|
Scott W. |
I have a lint.xml file that specifies a certain warning should be treated as an error
|
Scott W. |
specifically UnusedResources
|
Mark M. |
OK
|
Scott W. |
I want to add other issues to the list and mark them as errors, but they are not available. I want to add Android warnings to the list
|
Scott W. |
but it seems to only work with Java warnings
|
Mark M. |
I am not certain what you mean by "Android warnings" and "Java warnings". Are you referring to those code inspections that you mentioned earlier?
|
Scott W. |
correct
|
Mark M. |
basically, there are two systems for static code analysis at play here: Lint and Android Studio/IDEA code inspections
|
Mark M. |
Lint is available from outside of the IDE; code inspections are not
|
Scott W. |
ok
|
Mark M. |
and lint.xml is for Lint
|
Scott W. |
I see
|
Mark M. |
it's kinda confusing
|
Scott W. |
well, how can I fail builds for these various code inspections?
|
Sep 26 | 8:55 AM |
Mark M. |
see if there is an equivalent Lint rule, or create a Lint rule, or use some other tool that supplies that sort of analysis
|
Mark M. |
if all you want to do is fail builds in the IDE, you can adjust the behavior of the inspection
|
Mark M. |
but I am assuming that you want to fail builds everywhere (e.g., CI server)
|
Scott W. |
well failing them locally would be a good first step
|
Mark M. |
in Settings > Inspections, you can choose the severity level for a given inspection
|
Mark M. |
I don't know if that will "fail the build", but it at least affects color-coding
|
Scott W. |
when I choose Run 'app', I want it to say "NO"
|
Scott W. |
I'll play around with those settings and see what that does.
|
Mark M. |
sorry, but I have not played with changing inspection severities to know for certain if it will block the build
|
Mark M. |
my knowledge of this stuff comes mostly in the area of filing bug reports
|
Mark M. |
if I file it against Lint, it's almost guaranteed to actually be a code inspection
|
Mark M. |
if I file it against Studio, it's almost guaranteed to be really a Lint issue
|
Sep 26 | 9:00 AM |
Scott W. |
ok changing the severity adds a red squiggle under the relevant bit of code, but no fail.
|
Mark M. |
I was afraid that might be the case
|
Scott W. |
we use Travis for CI. Is it possible that Travis can use some other code inspection tool and catch this stuff?
|
Mark M. |
well, there are a variety of static analysis tools for Java and Kotlin
|
Mark M. |
those that integrate into Gradle can fail the build
|
Sep 26 | 9:05 AM |
Mark M. |
for example, ktlint confirms that your Kotlin code adheres to the official style, and rxlint confirms that you have error handlers on all your RxJava chains
|
Mark M. |
https://android-arsenal.com/tag/94?sort=created contains a bunch of these
|
Mark M. |
you can also create custom Lint rules, though that is not well documented
|
Scott W. |
yeah that's a bit more involved than I want to get into right now.
|
Scott W. |
I'm going to tinker around in Android Studio and see what I can get done.
|
Sep 26 | 9:10 AM |
Scott W. |
Is there a way to run the Android Studio code inspection from the command line?
|
Mark M. |
AFAIK, no
|
Mark M. |
however, Studio is really using IDEA here, so you might hunt around to see if there is an IDEA solution that happens to work with Studio
|
Scott W. |
good tip. I'm getting somewhere now
|
Sep 26 | 9:20 AM |
Scott W. |
ok I've got it doing the inspection from the command line. However, Android Studio can't be open when I run the command.
|
Mark M. |
that might still be OK for Travis, though
|
Scott W. |
well will Travis have Android Studio though?
|
Mark M. |
CI servers are usually servers
|
Scott W. |
this relies on an sh file packaged with Android Studio
|
Mark M. |
ah, I see
|
Mark M. |
you'd need to decipher enough of that shell script to see what it depends on
|
Mark M. |
most likely, it uses Java and some JARs from the IDE
|
Mark M. |
so while the Travis server won't have Studio, if it is your own server, you could arrange to either get Studio there or at least get those JARs there
|
Mark M. |
if this is a hosted CI-as-a-service thing, though, you would have to see what options they have for this level of customization
|
Scott W. |
I see. I'll talk to the guy that manages Travis about that.
|
Sep 26 | 9:25 AM |
Mark M. |
hopefully the guy that manages Travis is not named Travis, as that would get confusing
|
Scott W. |
Thanks for the guidance!
|
Mark M. |
you're welcome!
|
Scott W. |
:)
|
Scott W. |
talk to ya later
|
Mark M. |
have a pleasant day!
|
Scott W. | has left the room |
Sep 26 | 9:30 AM |
Mark M. | turned off guest access |