gradle版本与android的gradle插件版本兼容Unable to find method org.gradle.api.tasks.compile.CompileOptions.setB

今天踩了一个gradle版本的坑,记录一下


一、编译报错,如下完整报错日志:

编译失败ERROR:Unable to find method 'org.gradle.api.tasks.compile.CompileOptions.setBootClasspath

ERROR: Unable to find method 'org.gradle.api.tasks.compile.CompileOptions.setBootClasspath(Ljava/lang/String;)V'.
Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)

The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)

Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

二、编译失败的原因:

因为android的gradle插件com.android.tools.build:gradle的版本,依赖gradle的版本。

如下截图。我的gradle版本是5.4.1。com.android.tools.build:gradle的版本是3.0.1

根据android官方文档,我们找到了版本对应关系: https://developer.android.google.cn/studio/releases/gradle-plugin#updating-plugin

三、解决编译问题:

方法1:gradle版本降到4.1
方法2:将android的gradle插件升级到3.5.0~3.5.3

如下,我选择方法2,升级com.android.tools.build:gradle插件到3.5.3

编译成功,搞定。





赞美是一种美德,点个赞 再走啊,老铁


参考资料:
https://juejin.im/post/5ecb0b906fb9a047f845c422

https://developer.android.google.cn/studio/releases/gradle-plugin#updating-plugin

https://github.com/libgdx/libgdx/issues/5617

猜你喜欢

转载自blog.csdn.net/jiese1990/article/details/106417314
今日推荐