我希望在使用 gradle 构建时检查 strings.xml
的拼写。由于我们使用持续集成,因此我们需要将其配置为从命令行构建,而不仅仅是在 Android Studio 中。有什么办法吗?
附言。我试过:
lintOptions {
abortOnError false
// check *only* the given issue id's
check 'Typos'
}
字符串.xml:
<resources>
<string name="app_name">Project</string>
<!-- Common Words -->
<string name="test_spelling">sdfsdfdfds</string>
和
./gradlew assembleDebug lint
但一无所获:
:app:lint
Ran lint on variant release: 0 issues found
Ran lint on variant debug: 0 issues found
Wrote HTML report to file:/Users/asmirnov/Documents/dev/src/Project/app/build/outputs/lint-results.html
Wrote XML report to /Users/asmirnov/Documents/dev/src/Project/app/build/outputs/lint-results.xml
我还检查了 lint --show
:
...
Typos
-----
Summary: Spelling error
Priority: 7 / 10
Severity: Warning
Category: Correctness:Messages
This check looks through the string definitions, and if it finds any words
that look like likely misspellings, they are flagged.
...
PPS。如果我添加另一个规则来检查(check 'Typos', 'TypographyEllipsis'
),我会按预期收到警告(对于 TypographyEllipsis
),所以一般情况下 linting 工作。出于某种原因,“拼写错误”规则仅不起作用
最佳答案
我目前正在做类似的事情,所以还没有完成我的工作。不确定您是否有答案,就像刚才问的那样。这是我的。
你在这里的代码:
lintOptions {
abortOnError false
// check *only* the given issue id's
check 'Typos'
}
应该没问题。如果您正在使用它们,您也可以将它添加到一个 flavor 中,以限制更多。
要从命令行获取报告,需要执行:
./gradlew lintAssembleDebug
或任何您喜欢的口味,例如./gradlew lintAssembleMyFlavorDebug
我正在尝试使用 lintOptions.check()
方法以编程方式添加我想要的检查,但还没有成功。另一种选择如所述here杰森阿特伍德。我正在看这个,添加空白文件:
ext.lintCheckList = [
// Blank default list
] as String[]
到 repo,并根据需要在 CI 作业中替换它。
希望对您有所帮助。
更新:
命令不正确。应该是
./gradlew lintDebug
或
./gradlew lintMyFlavorDebug
等等
关于android - 有什么方法可以配置 gradle 来检查 strings.xml 中的拼写吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36056347/