I've read a lot about the StopShip
Android Lint Check and Gradle support for it
I would like to use as some here in SO have already mentioned, instead of a TODO or FIXME comment, use it to ensure a code block intended for development/debugging/testing does not reach production.
For this, I would like to do 2 things: - enable StopShip check, as it is disable by default - change severity from warning (default) to error
(assuming that we use abortOnError true
on our gradle config).
I am failing to achieve this! No matter what I tried android build does not fails if I add a // STOPSHIP
comment in my code. Which is odd, since in the textEditor its highlighted as an error and if I run a Lint check (Analyze > Inspect Code...) it is listed as one of the issues.
Here's what I've tried in my build.gradle
lintOptions {
checkReleaseBuilds true
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError true
enable 'StopShip'
error 'StopShip'
}
I have also tried to change my Android Studio preferences in File > Settings > Project Settings > Inspections (or Android Studio > Preferences > Inspections on Mac). Here I checked the Code contains STOPSHIP marker
and changed the severity to error but still nothing.
Here's what my lint.xml
looks like:
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="BackButton" severity="warning" />
<issue id="EasterEgg" severity="warning" />
<issue id="FieldGetter" severity="warning" />
<issue id="IconExpectedSize" severity="warning" />
<issue id="RtlCompat" severity="error" />
<issue id="RtlEnabled" severity="warning" />
<issue id="RtlHardcoded" severity="warning" />
<issue id="SelectableText" severity="warning" />
<issue id="StopShip" severity="error" />
<issue id="TypographyQuotes" severity="warning" />
<issue id="UnusedIds" severity="warning" />
</lint>
Whether lint should check for fatal errors during release builds. Default is true. If issues with severity "fatal" are found, the release build is aborted.
Better solution is solving problem in your code, because lint tool checks your Android project source files for potential bugs and optimization improvements for correctness, security, performance, usability, accessibility, and internationalization.
Improve your code with lint checks 1 Overview 2 Run lint from the command line 3 Configure lint to suppress warnings 4 Configure lint options with Gradle 5 Create warnings baseline 6 Manually run inspections
If your project includes build variants, and you instead want to run the lint task for only a specific build variant, you must capitalize the variant name and prefix it with lint . To learn more about running Gradle tasks from the command line, read Build Your App from the Command Line .
I finally cracked it! fatal 'StopShip'
. That's what finally did it! Leaving my discovery in case it helps anyone.
Replacing error 'StopShip'
with fatal 'StopShip'
in my build.gradle
config solved the problem.
I don't fully understand why my previous attempts with error 'StopShip'
didn't work, as the abortOnError docs clearly state:
Whether lint should set the exit code of the process if errors are found
and I was marking the StopShip
check severity as error. It looks like abortOnError
will only make the Gradle build abort for FATAL errors. Can anyone confirm?
Of course, if it anyone offers a better solution/explanation, please do share.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With