低调路人甲
低调路人甲
  • 发布:2026-04-03 17:57
  • 更新:2026-04-03 18:17
  • 阅读:40

uts插件引入第三方依赖usb-serial-for-android运行报错Could not find

分类:uts

config.json

{  
  "minSdkVersion": "23",  
  "dependencies": [  
    "com.github.mik3y:usb-serial-for-android:3.10.0"  
  ],  
  "project": {  
    "dependencies": [  
      "com.github.mik3y:usb-serial-for-android:3.10.0"  
    ]  
  }  
}

uni_modules/demo-plugin/utssdk/app-android里面写了个Demo.kt

package uts.sdk.modules.demoPlugin  

import android.content.Context  
import android.hardware.usb.UsbManager  
import com.hoho.android.usbserial.driver.UsbSerialPort  
import com.hoho.android.usbserial.driver.UsbSerialProber  
import com.hoho.android.usbserial.util.HexDump  
import com.hoho.android.usbserial.util.SerialInputOutputManager  
import io.dcloud.uts.UTSAndroid  
import io.dcloud.uts.console

运行报错

uni_module [demo-plugin] 正在更新三方依赖...  
17:53:02.557 uni_module [demo-plugin]   
17:53:02.557 FAILURE: Build failed with an exception.  
17:53:02.557 * What went wrong:  
17:53:02.557 Execution failed for task ':androidDependencies'.  
17:53:02.557 > Could not resolve all artifacts for configuration ':debugCompileClasspath'.  
17:53:02.557    > Could not resolve all dependencies for configuration ':debugCompileClasspath'.  
17:53:02.558       > Could not find com.github.mik3y:usb-serial-for-android:3.10.0.  
17:53:02.558         Required by:  
17:53:02.558             root project :  
17:53:02.559 * Try:  
17:53:02.559 > The project declares repositories, effectively ignoring the repositories you have declared in the settings.  
17:53:02.559    To determine how project repositories are declared, configure your build to fail on project repositories.  
17:53:02.559    For more information, please refer to https://docs.gradle.org/8.14.4/userguide/declaring_repositories.html#sub:fail_build_on_project_repositories in the Gradle documentation.  
17:53:02.559 > Run with --stacktrace option to get the stack trace.  
17:53:02.560 > Run with --info or --debug option to get more log output.  
17:53:02.560 > Run with --scan to get full insights.  
17:53:02.560 > Get more help at https://help.gradle.org.  
17:53:02.560 BUILD FAILED in 1m 22s  
17:53:14.737 uts插件[demo-plugin]编译失败  
17:53:14.738 ‌error: 找不到名称“hoho”。参考: https://doc.dcloud.net.cn/uni-app-x/uts/compiler-known-issues.html#error18‌

com.hoho是在com.github.mik3y:usb-serial-for-android:3.10.0这个依赖里的,这个包存在但却下载不下来。

2026-04-03 17:57 负责人:无 分享
已邀请:
Ask小助手

Ask小助手

该问题是因为缺少 JitPack 仓库配置导致 Gradle 无法解析 com.github.mik3y:usb-serial-for-android 依赖。

解决方案:

config.jsonproject.repositories 中添加 JitPack 仓库地址:

{  
  "minSdkVersion": "23",  
  "dependencies": [  
    "com.github.mik3y:usb-serial-for-android:3.10.0"  
  ],  
  "project": {  
    "repositories": [  
      "maven { url 'https://jitpack.io' }"  
    ],  
    "dependencies": [  
      "com.github.mik3y:usb-serial-for-android:3.10.0"  
    ]  
  }  
}

本助手使用国产模型,生成代码可能不准确。专业的代码生成需要全球顶尖的AI Coding模型。推荐使用uni-agent

原因说明:
com.github.mik3y:usb-serial-for-android 托管在 JitPack 上,默认情况下 UTS 插件的 Gradle 配置不包含 JitPack 仓库,因此会报 Could not find 错误。根据 UTS 插件配置文档,需要在 project.repositories 中显式声明该仓库。

补充建议:

如果仅需使用 USB 串口功能,建议直接使用插件市场已有的封装插件,无需自行封装:

  1. usb-serial-for-uniapp - 基于 usb-serial-for-android 的原生插件
  2. usb串口-usb-serial串口通信-UTS插件 - UTS 插件版本,支持 UniApp(X)

这些插件已处理好依赖配置和原生接口封装,可直接使用。

内容为 AI 生成,仅供参考
低调路人甲

低调路人甲 (作者)

加了 JitPack仓库地址依赖报错

要回复问题请先登录注册