Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Grade release build fail using Lint Option StopShip?

I've read a lot about the StopShip Android Lint Check and Gradle support for it

  • http://tools.android.com/tips/lint-checks
  • http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Lint-support
  • http://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.LintOptions.html#com.android.build.gradle.internal.dsl.LintOptions:checkReleaseBuilds
  • Android lint enable checks with gradle
  • gradle build fails on lint task
  • http://developer.android.com/tools/help/lint.html
  • http://developer.android.com/tools/debugging/improving-w-lint.html

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>
like image 763
acrespo Avatar asked Nov 03 '15 16:11

acrespo


People also ask

Should lint check for fatal errors during release builds?

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.

Why lint tool is used in Android development?

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.

How to improve your code with LINT checks with Gradle?

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

How do I run the lint task for specific build variants?

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 .


1 Answers

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.

like image 195
acrespo Avatar answered Oct 27 '22 13:10

acrespo