【问题标题】:Gradle build: Execution failed for task ':app:lint'Gradle build:任务':app:lint'的执行失败
【发布时间】:2023-03-15 06:55:02
【问题描述】:

我正在使用 Android Studio 2.0,当发生奇怪的事情时,我正在尝试运行我的程序。我运行了 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 来解决这个问题,但问题是:为什么我收到此错误消息?

请救救我!

【问题讨论】:

  • 你在发布吗?
  • 对不起,我不知道你所说的“内置发布”是什么意思...你能说得更具体点吗?
  • 您使用的是“Debug”还是“Release”构建类型?
  • 我正在调试模式下构建

标签: android android-studio gradle android-gradle-plugin android-studio-2.0


【解决方案1】:

将此添加到您的 app/build.gradle 文件中

android {
    //...
    lintOptions {
        abortOnError false
    }
}

【讨论】:

  • 我知道了,但我正在寻找错误的原因...为什么会出现?
  • 对于更多的查看者,请确保您引用了正确的build.gradle您的项目 - stackoverflow.com/questions/37250493/…
  • 当我尝试将此代码添加到 build.gradle 时,如果弹出警告消息“访问被拒绝”怎么办?
  • RN中有很多build.gradles,正如最后一个答案指定的那样,使用build.gradle(Module: app)
  • 是否有一个命令行开关可以像 abortOnError=false 一样临时使用而不将其永久添加到 build.gradle 文件中?
【解决方案2】:
  1. 切换到项目视图
  2. 然后,project/app/build/reports/lint-results
  3. 现在,您将找到两种格式的 lint-result 文件 - 1) xml 和 2) html。

您可以按原样查看这些文件。但是,我发现在浏览器中查看 lint 结果很容易。只需右键单击 html 文件并选择在浏览器中查看。

它在我的 Chrome 浏览器中打开,如下图所示。

【讨论】:

  • 而不是忽略。这是修复的正确方法。
  • 这个不错,以前我从来没有真正访问过构建文件夹,现在我会。
  • 是的。就我而言,它位于project/app/build/reports/lint-results-debug 文件中。
【解决方案3】:

在构建应用模块时遇到一些 lint 问题。

您可以在Project\module\build\outputs 生成的报告中找到所有问题。
在这里,您将找到带有 lint 报告的 html 文件和 xml 文件。

app\build.gradle中使用这个脚本

android {
    lintOptions {
        abortOnError false
    }
}

您可以禁用该阻止,但它不是最佳做法
您应该分析 lint 报告以解决每个问题。

【讨论】:

  • 感谢您指向报告。但是为什么这些警告没有集成到 Android Studio 中呢?我认为这个 IDE 比 ADT 好太多了。
  • 您应该指定您建议的短脚本添加属于 build.gradle 的 Module:app 部分。
  • @GabrieleMariotti 你是对的。不久之后我改变了主意,但已经很晚了:\如果您编辑您的答案,我将能够再次取消我的反对票:)
【解决方案4】:

我认为发现错误比忽略它们更好。

试试这个:

在 Gradle Console 中找到“Wrote HTML report to file”,打开指定的 HTML 文件,你会发现一个 lint 报告

找到你的错误并修复它们

【讨论】:

    【解决方案5】:

    你的 build.gradle(Module: app) 应该包括


    android {
        lintOptions {
            abortOnError false
        }
    }
    

    【讨论】:

      【解决方案6】:

      如果abortOnError false 不起作用,Flutter 2.5.1 版本建议在 lintOptions 中使用以下参数:

      android{
          ...
          lintOptions {
              checkReleaseBuilds false
          }
      }
      

      【讨论】:

        【解决方案7】:

        运行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 失败的原因。修复这些错误后,您的构建将顺利完成。

        【讨论】:

          【解决方案8】:

          我收到了错误Execution failed for task ':app:lintVital[myBuildVariant]' 和一个空指针错误。它发生在切换分支之后,对我有帮助的是做一个 Build -> Clean Project

          【讨论】:

            【解决方案9】:

            如果您遇到此问题,请不要在您的 gradle 中添加 linter disabler, 这是一个访问错误问题,我在对几个命令使用 sudo 命令后在 react-native 上遇到了这个问题, 只需重置您的代码访问权限,然后再次发布 比如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'
                ) 
            } 
            }
            

            因此,如果该库中存在错误,您可以在发布前修复错误

            【讨论】:

              【解决方案10】:

              只在 build gradle 中添加此代码:

              android {
                  lintOptions {
                      abortOnError false
                  }
              }
              

              应该够了。

              【讨论】:

                猜你喜欢
                • 2021-08-07
                • 2020-03-16
                • 1970-01-01
                • 2014-10-25
                • 2013-07-09
                • 1970-01-01
                • 1970-01-01
                • 2013-12-08
                • 1970-01-01
                相关资源
                最近更新 更多