如何使用Lint Option StopShip使Grade发布版本失败?

acr*_*spo 12 android gradle android-lint build.gradle android-gradle-plugin

我已经阅读了很多关于StopShipAndroid Lint Check和Gradle支持的内容

我想使用SO中的一些已经提到的,而不是TODO或FIXME注释,使用它来确保用于开发/调试/测试的代码块不能达到生产.

为此,我想做两件事: - 启用StopShip检查,因为它默认是禁用 - 将严重性从警告(默认)更改为错误

(假设我们abortOnError true在gradle配置上使用).

我没能做到这一点!无论我尝试什么,如果我// STOPSHIP在代码中添加注释,android构建都不会失败.这很奇怪,因为在textEditor中它突出显示为错误,如果我运行Lint检查(Analyze> Inspect Code ...),它将被列为问题之一.

这就是我在我的尝试中所做的 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'
}
Run Code Online (Sandbox Code Playgroud)

我还尝试在"文件">"设置">"项目设置">"检查"(或Android中的Android Studio>"首选项">"检查")中更改我的Android Studio首选项.在这里,我检查Code contains STOPSHIP marker并将严重性更改为错误,但仍然没有.

这是我的lint.xml样子:

<?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>
Run Code Online (Sandbox Code Playgroud)

acr*_*spo 12

我终于搞砸了!fatal 'StopShip'.这就是最终做到的!离开我的发现,万一它可以帮助任何人.

更换error 'StopShip'fatal 'StopShip'在我build.gradle的配置解决了这个问题.

我不完全理解为什么我以前的尝试error 'StopShip'不起作用,因为abortOnError文档清楚地说明:

lint是否应该在发现错误时设置进程的退出代码

我将StopShip检查严重性标记为错误.看起来abortOnError只会使Gradle构建中止FATAL错误.谁能确认一下?

当然,如果有人提供更好的解决方案/解释,请分享.

  • “ StopShip”的默认值为“警告”,而“ error”和“致命”对我的工作方式与“ abortOnError”相结合的方式与预期的一样。(使用Gradle插件1.5.0) (2认同)