使用Lint Option StopShip如何使版本发布失败? [英] How to make Grade release build fail using Lint Option StopShip?
问题描述
我已阅读了很多有关 StopShip
Android Lint Check和Gradle支持的文章。
- http://tools.android.com/tips/lint-checks
- http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Lint-support
- < a href =http://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.LintOptions.html#com.android.build.gradle.internal.dsl。 LintOptions:checkReleaseBuildsrel =nofollow noreferrer> 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 che cks with gradle
- gradle build lint任务失败
- http ://developer.android.com/tools/help/lint.html
- http://developer.android.com/tools/debugging/improving-w-lint.html
ul>
我想在SO中使用一些已经提到的,而不是TODO或FIXME评论,使用它来确保用于开发/调试/测试的代码块没有达到生产。
为此,我想做两件事:
- 启用StopShip检查,因为它默认为禁用
- (假设我们在gradle配置中使用 abortOnError true
),将严重性从警告(默认)更改为错误。
我无法达到这个目标!无论我尝试过如何在代码中添加 // STOPSHIP
注释,都不会失败。这很奇怪,因为在textEditor中它的突出显示为错误,如果我运行Lint检查(Analyze> Inspect Code ...),它被列为其中一个问题。
以下是我在 build.gradle中试过的内容
lintOptions {
看起来像:
checkReleaseBuilds true
//或者,如果您愿意,您可以继续检查发布版本中的错误,
//但即使在发现错误时仍继续构建:
abortOnError true
启用StopShip
错误StopShip
code $ b我也尝试在文件>设置>项目设置>检查(或Mac上的Android Studio>首选项>检查)中更改我的Android Studio首选项。在这里我检查了
代码包含STOPSHIP标记
,并将严重性更改为错误,但仍然没有任何结果。
code> lint.xml
<?xml version =1.0 encoding =UTF-8?>
< lint>
< issue id =BackButtonseverity =warning/>
< issue id =EasterEggseverity =warning/>
< issue id =FieldGetterseverity =warning/>
< issue id =IconExpectedSizeseverity =warning/>
< issue id =RtlCompatseverity =error/>
< issue id =RtlEnabledseverity =warning/>
< issue id =RtlHardcodedseverity =warning/>
< issue id =SelectableTextseverity =warning/>
< issue id =StopShipseverity =error/>
< issue id =TypographyQuotesseverity =warning/>
< issue id =UnusedIdsseverity =warning/>
< / lint>
解决方案我终于破解了它!
致命'StopShip'
。这就是最终做到的!
使用
替换
在我的错误'StopShip'
致命'StopShip'build.gradle
config中解决了这个问题。
I don不能完全理解为什么我之前尝试使用
错误'StopShip'
不起作用,因为 abortOnError docs 清楚地表明:
如果发现错误,lint是否应设置进程的退出代码
blockquote>
并且我将
StopShip
检查严重性标记为错误。它看起来像abortOnError
只会让Gradle生成中止致命错误。任何人都可以确认吗?
当然,如果有人提供更好的解决方案/解释,请分享。
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>
解决方案I finally cracked it!
fatal 'StopShip'
. That's what finally did it! Leaving my discovery in case it helps anyone.Replacing
error 'StopShip'
withfatal 'StopShip'
in mybuild.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 likeabortOnError
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.
这篇关于使用Lint Option StopShip如何使版本发布失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!