Gradle 构建:任务 ':app:lint' 执行失败
Gradle build: Execution failed for task ':app:lint'
我正在使用 Android Studio 2.0,当我试图 运行 我的程序时,发生了一些事情 运行ge。我 运行 gradle 的构建命令,我得到了这个错误:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:lint'.
> Lint found errors in the project; aborting build.
Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}
...
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 4.197 secs
Lint found errors in the project; aborting build.
Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}
...
10:41:28: External task execution finished 'build'.
所以...那到底是什么?我应该通过将代码添加到 gradle.build 来解决这个问题,但问题是:为什么我收到此错误消息?
大家救救我吧!
将此添加到您的 app/build.gradle
文件中
android {
//...
lintOptions {
abortOnError false
}
}
您在构建应用程序模块时遇到一些 lint 问题。
您可以找到在 Project\module\build\outputs
生成的报告中发现的所有问题。
在这里您会找到 html 文件和带有 lint 报告的 xml 文件。
在 app\build.gradle
中使用此脚本
android {
lintOptions {
abortOnError false
}
}
您可以禁用 阻止,但这不是最佳做法。
您应该分析 lint 报告以解决每个问题。
您的 build.gradle(模块:应用) 应包括
android {
lintOptions {
abortOnError false
}
}
我认为发现错误比忽略错误更好。
试试这个:
在Gradle控制台中找到“Wrote HTML report to file”,打开指示的HTML文件,你会发现一个lint报告
找到你的错误并修正它们
运行 gradle build -i
而不仅仅是 gradle build
。会有比平时更多的输出。其中一些看起来像这样:
> Task :project-name:lint FAILED
Putting task artifact state for task ':project-name:lint' into context took 0.0 secs.
Up-to-date check for task ':project-name:lint' took 0.0 secs. It is not up-to-date because:
Task has not declared any outputs.
Ran lint on variant release: 333 issues found
Ran lint on variant debug: 333 issues found
Wrote HTML report to file:///some/path/lint-results.html
Wrote XML report to file:///some/pahth/lint-results.xml
:project-name:lint (Thread[Task worker for ':',5,main]) completed. Took 1.756 secs.
检查 /some/path/lint-results.html
以了解 lint 失败的原因。修复这些错误后,您的构建将顺利完成。
- 切换到项目视图
- 然后,project/app/build/reports/lint-results
- 现在,您会发现 lint-result 文件有两种格式 - 1) xml 和 2) html。
您可以按原样查看这些文件。但是,我发现在浏览器中查看 lint 结果对眼睛来说很容易。只需在 html 文件上 right-click 并选择在浏览器中查看。
它在我的 Chrome 浏览器中打开如下图所示。
我收到错误 Execution failed for task ':app:lintVital[myBuildVariant]'
和空指针错误。它发生在切换分支之后,对我有帮助的是做一个 Build -> Clean Project
仅在构建 gradle 中添加此代码:
android {
lintOptions {
abortOnError false
}
}
应该够了。
如果您遇到此问题,请不要向您的 gradle 添加 linter 禁用器,
这是一个访问错误问题,我在 react-native 上使用 sudo 命令执行了几个命令后遇到了这个问题,
只需重置您的代码访问权限,然后再次释放
例如 mac
sudo chmod -R 777 <project-root-folder-name>
如果仍然使用
preBuild.doFirst {
ant.replaceregexp(
match:'Bad gradle',
replace:'Correct one',
flags:'g',
byline:true
) {
fileset(
dir: 'Where to search',
includes: '*.java'
)
}
}
因此,如果该库中存在错误,您可以在发布前修复错误
如果abortOnError false
不起作用,Flutter 2.5.1版本建议在lintOptions中使用以下参数:
android{
...
lintOptions {
checkReleaseBuilds false
}
}
新的lint方式是这样的
android {
lint {
isAbortOnError = false
}
}
我正在使用 Android Studio 2.0,当我试图 运行 我的程序时,发生了一些事情 运行ge。我 运行 gradle 的构建命令,我得到了这个错误:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:lint'.
> Lint found errors in the project; aborting build.
Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}
...
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 4.197 secs
Lint found errors in the project; aborting build.
Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
lintOptions {
abortOnError false
}
}
...
10:41:28: External task execution finished 'build'.
所以...那到底是什么?我应该通过将代码添加到 gradle.build 来解决这个问题,但问题是:为什么我收到此错误消息?
大家救救我吧!
将此添加到您的 app/build.gradle
文件中
android {
//...
lintOptions {
abortOnError false
}
}
您在构建应用程序模块时遇到一些 lint 问题。
您可以找到在 Project\module\build\outputs
生成的报告中发现的所有问题。
在这里您会找到 html 文件和带有 lint 报告的 xml 文件。
在 app\build.gradle
android {
lintOptions {
abortOnError false
}
}
您可以禁用 阻止,但这不是最佳做法。
您应该分析 lint 报告以解决每个问题。
您的 build.gradle(模块:应用) 应包括
android {
lintOptions {
abortOnError false
}
}
我认为发现错误比忽略错误更好。
试试这个:
在Gradle控制台中找到“Wrote HTML report to file”,打开指示的HTML文件,你会发现一个lint报告
找到你的错误并修正它们
运行 gradle build -i
而不仅仅是 gradle build
。会有比平时更多的输出。其中一些看起来像这样:
> Task :project-name:lint FAILED
Putting task artifact state for task ':project-name:lint' into context took 0.0 secs.
Up-to-date check for task ':project-name:lint' took 0.0 secs. It is not up-to-date because:
Task has not declared any outputs.
Ran lint on variant release: 333 issues found
Ran lint on variant debug: 333 issues found
Wrote HTML report to file:///some/path/lint-results.html
Wrote XML report to file:///some/pahth/lint-results.xml
:project-name:lint (Thread[Task worker for ':',5,main]) completed. Took 1.756 secs.
检查 /some/path/lint-results.html
以了解 lint 失败的原因。修复这些错误后,您的构建将顺利完成。
- 切换到项目视图
- 然后,project/app/build/reports/lint-results
- 现在,您会发现 lint-result 文件有两种格式 - 1) xml 和 2) html。
您可以按原样查看这些文件。但是,我发现在浏览器中查看 lint 结果对眼睛来说很容易。只需在 html 文件上 right-click 并选择在浏览器中查看。
它在我的 Chrome 浏览器中打开如下图所示。
我收到错误 Execution failed for task ':app:lintVital[myBuildVariant]'
和空指针错误。它发生在切换分支之后,对我有帮助的是做一个 Build -> Clean Project
仅在构建 gradle 中添加此代码:
android {
lintOptions {
abortOnError false
}
}
应该够了。
如果您遇到此问题,请不要向您的 gradle 添加 linter 禁用器, 这是一个访问错误问题,我在 react-native 上使用 sudo 命令执行了几个命令后遇到了这个问题, 只需重置您的代码访问权限,然后再次释放 例如 mac
sudo chmod -R 777 <project-root-folder-name>
如果仍然使用
preBuild.doFirst {
ant.replaceregexp(
match:'Bad gradle',
replace:'Correct one',
flags:'g',
byline:true
) {
fileset(
dir: 'Where to search',
includes: '*.java'
)
}
}
因此,如果该库中存在错误,您可以在发布前修复错误
如果abortOnError false
不起作用,Flutter 2.5.1版本建议在lintOptions中使用以下参数:
android{
...
lintOptions {
checkReleaseBuilds false
}
}
新的lint方式是这样的
android {
lint {
isAbortOnError = false
}
}