[Bug]org.gradle.api.GradleException: Lint found fatal errors while assembling a release target

一、Bug log

org.gradle.execution.MultipleBuildFailures: Build completed with 1 failures.
	at org.gradle.......
	......
Caused by: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:lintVitalRelease'.
	at org.gradle......
	......
	
Caused by: org.gradle.api.GradleException: Lint found fatal errors while assembling a release target.

To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}
...
	at com.android.tools.lint.gradle.Lint.....
	......

二、Bug描述

  • 在编辑正式包时,报出上面的错误log
  • 根据Caused by: org.gradle.api.GradleException: Lint found fatal errors while assembling a release target.获知,该错误是lint检查到了致命错误,导致编译正式包失败
  • 一般为res下的资源文件出错

三、解决

1、不完美的解决(不推荐)

按照报错提示,在module的gradle文件中,添加如下代码,忽略lint检查发现的错误:

android {
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}

当然,这是不严谨、不可取的…
然而as没有给出更多的较明确的错误提示,怎么办?请看下面的解决办法。

2、排查解决(推荐)

lint检查的错误会生成错误报告,查看当前module的/build/reports/文件夹中lint-results-release-fatal.html文件,以网页形式打开,将看到非常详细的报错,例如下图:
[Bug]org.gradle.api.GradleException: Lint found fatal errors while assembling a release target_第1张图片

  • 以上截图仅作为示例,你的项目报错的详细原因可能与截图不同
  • 这个问题大概是因为,之前这些组件是在某个RelativeLayout中的,后来因为UI改动,不在之前的RelativeLayout中了,或者被依赖位置的组件不在之前的RelativeLayout中了,但是没有将关联位置的id设置删除
  • lint检查的问题类型有很多,报出的问题应尽力查看详细报告排查清楚

你可能感兴趣的:(Android零碎)