今天踩了一个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

点击阅读全文
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐