Error:org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; 解决

一、前言:

编译时直接报错“Error:org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.”

image.png

在 gradle 中查看详情时的错误,变成“Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.”

在 gradle 中查看错误具体原因如下图:

image.png

注意这一行

javacTask: 源发行版 1.8 需要目标发行版 1.8

二、解决方法:

1. 分析原因:

由于我在写 lamdba 表达时是,爆出“lambda expressions are not supported at this language level”这个错误
,所以更改了Source Compatibility的版本是 1.8 和Target Compatibility 的版本不一致,
如下图所示:


image.png

2. 具体解决:

修改 Source Compatibility 和Target Compatibility 必须选择版本一致即可。

如下图所示:

image.png

这样项目就可以正常运行了。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容