首页 APP开发 正文内容

uni-app 运行官方的 hello-uts 项目报 gradle 错误

2023年12月16日 , , 1,064

学习 UTS 插件开发都是从运行官方的 Hello-UTS 项目开始,不过有时候本地运行也会失败的,本文讲述其中一种情况的解决方法。

有朋友刚想学习 uni-app 的 UTS 插件开发,看完一篇文档后就下载官方的 Hello-UTS 项目到本地电脑,项目初始化并且安装完依赖和 android studio 后,在 HbuiderX 中运行项目到模拟器时,没有成功,而是报错了。

报错信息

14:17:34.085 uts插件[uts-hello-component]文件未发生变化,跳过编译
14:17:51.601 uni_module [uts-tencentgeolocation] Enron:
14:17:51.605 FAILURE: Build failed with an exception.
14:17:51.605 * What went wrong:
14:17:51.609 Execution failed for task "androidDependencies'.
14:17:51.618 Failed to notify dependency resolution listener.
14:17:51.618 > Failed to notify dependency resolution listener.
14:17:51.621 > void org.gradle.api.artifacts.DependencySubstitutions$Substitution with(org.gradle.api.artifacts.component.ComponentSelector)*
void org.gradle.api.artifacts.DependencySubstitutions$Substitution with(org.gradle.api.artifacts.component.ComponentSelector)
14:17:51.625 * Try:
14:17:51.629 Run with snacktrace pugnton to get mock tog output.
14:17:51.636 Run with --scan to get full insights.
14:17:51.642 Get more help at https://help.gradle.org.
...
hello-uts 运行报错截图
hello-uts 运行报错截图

报错分析

我一开始以为是模拟器的问题,后来我朋友尝试运行到安卓真机上,仍然失败,报一样的错误,排除模拟器的问题。

然后再从报错信息中的 https://help.gradle.org 猜测应该是 gradle 版本的问题,后来去翻看 UTS 相关的文档,发现安卓版本的 UTS 目前还不支持 8.x 版本 gradle,最高只支持到了 7.x版本。朋友一看本机的 gradle 果然是 8.2 版本。

解决方法

知道了报错的原因,解决方法就很简单了,重新下载 gradle 7.x 版本,然后在重新运行 Hello-UTS 项目,就成功了。

PS:UTS 上手还是需要时间,在自己没能熟练编写代码时,建议多看 Hello-UTS 里面的示例代码,能大大提高学习的速度。