gpt4 book ai didi

android - 如何使用 Lint Option StopShip 使 Grade 发布构建失败?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:03:33 26 4
gpt4 key购买 nike

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

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

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

(假设我们在我们的 gradle 配置中使用了 abortOnError true)。

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

这是我在我的 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'
}

我还尝试在"file">“设置”>“项目设置”>“检查”(或 Android Studio >“首选项”>“Mac 上的检查”)中更改我的 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>

最佳答案

我终于破解了! 致命的“StopShip”。终于做到了!留下我的发现,以防它对任何人有帮助。

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

我不完全理解为什么我之前尝试使用error 'StopShip' 失败,因为 abortOnError docs明确说明:

Whether lint should set the exit code of the process if errors are found

我将 StopShip 检查严重性标记为错误。看起来 abortOnError 只会让 Gradle 构建因 fatal error 而中止。谁能证实一下?

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

关于android - 如何使用 Lint Option StopShip 使 Grade 发布构建失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33504186/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com