问题描述
我想在Android Studio中为 release 和 debug 构建类型使用不同的 lint.xml 文件.那么,如何实现呢?
I want to use different lint.xml files for release and debug build types in Android Studio. So, how can this be achieved?
当我将 lint.xml 放在 someModule/src/debug 和 someModule/src/release 文件夹中时(这些文件夹仅包含该 lint.xml 文件,仅此而已)gradle会做出反应,因为没有任何 lint.xml 文件,如果我放置单个 lint.xml 文件在核心模块文件夹(someModule/)下-gradle可以识别它,但是在这种情况下,根据构建类型,我不能使用其他设置...
When I place lint.xml in someModule/src/debug and someModule/src/release folders (also, these folders contain only that lint.xml file and nothing more) gradle reacts as there is no any lint.xml file, If I place single lint.xml file under core module folder (someModule/)- gradle recognizes it, but in this case I can't use different settings depending on build type...
推荐答案
以下是对我有用的东西:
Here's what worked for me:
tasks.whenTaskAdded { task ->
if (task.name.startsWith("lint")) {
if (task.name.toLowerCase().endsWith("release")) {
task.doFirst {
android.lintOptions.abortOnError = true
}
} else {
task.doFirst {
android.lintOptions.abortOnError = false
}
}
}
}
在我的情况下,我需要打开 abortOnError
进行发行版本构建,以便我可以自由开发,但可以在CI上快速捕获棉绒错误(如果它们滑倒了).
In my case I needed to turn on abortOnError
for release builds so that I can develop freely but catch lint errors quickly on my CI (if they slipped).
这篇关于Android Studio中不同构建类型的不同lint.xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!