[经验分享] 【TOOLS使用】OpenHarmony命令行工具hdc安装应用指南 原创 精华

诚迈_雨哥 显示全部楼层 发表于 2023-12-14 21:19:42

OpenHarmony Command Line Tool HDC Installation and Application Guide

一、工具概述

hdc(OpenHarmony Device Connector)是为开发人员提供的用于设备连接调试的命令行工具,该工具需支持部署在Windows/Linux/Mac等系统上与OpenHarmony设备(或模拟器)进行连接调试通信。 简言之,hdc是OpenHarmony提供的用于开发人员调试硬件、应用的命令行工具,用在电脑与开发板之间的交互。 适用于OpenHarmony应用、硬件开发及测试人员,是每个开发人员的必备、入门工具。

二、环境准备

  1. 环境要求 本文以window10电脑和Rk3568开发板为例进行说明。linux版本建议ubuntu 18.04以上 64位,其他相近版本也可;libc++.so引用错误请使用ldd/readelf等命令检查库引用 windows版本建议windows10 64位,如果低版本windows winusb库缺失,请使用zadig更新库。

  2. 安装USB设备驱动安装 第一步,连接PC与开发板USB线PC与开发板通过USB调试线连接,开发板上运行开源系统主线版本。连接端口如蓝色线缆所示

    微信图片_20231214165123.jpg第二步,安装USB驱动DriverAssitant 是RK3568 开发板自带的 USB驱动。双击 DriverInstall.exe,选择驱动安装。

    install_driver.PNG

    第三步,设备管理器查看驱动是否安装成功未连接USB先或者驱动未安装成功如图片左边所示,成功则如右边所示,会出现”hdc Device”。

    connectok.PNG

  3. hdc工具下载

    第一步,下载安装包

    链接:http://ci.openharmony.cn/workbench/cicd/dailybuild/dailylist 查找“流水线名称”名称为 ohos-sdk-full, 或者 ohos-sdk-public,点击‘下载链接’,选择‘全量包’

    download-hdc.PNG

    download-hdc-full.PNG

    第二步,解压缩任意一个选择红框中的文件第三步,拷贝至D:\hdc_bin\目录下注意:无须双击安装

    hdcextPNG.PNG

  4. hdc 路径环境配置 hdc path环境配置如图所示。我的电脑,右键选择属性,选择“高级系统设置”→高级→环境设置→系统环境变量中的 path→输入“D:\hdc_bin”→ 一路“确定”

    env.PNG

    edit_path.PNG

  5. 至此,hdc可以正常运行了 打开cmd窗口,执行 hdc shell 就进入命令交互界面。

三、hdc 功能列表

序号 命令 功能描述 成功输出
1 hdc -v 查看工具版本 Ver: 1.1.2a
2 hdc -h 查看工具帮助 OpenHarmony device connector(HDC) ...
3 hdc list targets 查看已连接设备 7001005458323933328a250efe593900
4 hdc list targets -v 查看连接设备详细信息 7001005458323933328a250efe593900 USB Connected localhost
5 hdc shell 进入命令行交互环境 #
6 hdc shell mount -o rw,remount 挂在系统目录 tmpfs on /dev type tmpfs (rw,seclabel,nosuid,relatime,size=990956k,nr_inodes=247739,mode=755)...
7 hdc file send d:\test.txt /data/ 从PC拷入文件到开发板(往设备中推送文件) FileTransfer finish, Size:xxx time:26ms rate:xxxkB/s
8 hdc file recv /data/test.txt c:\test.txt 从开发板拷出文件到PC(从设备中拉取文件) FileTransfer finish, Size:xxx time:51ms rate:xxxkB/s
9 hdc install D:\test.hap 安装HAP应用 [Info]App install path:D:\test.hap, queuesize:0, msg:install bundle successfully.<br>AppMod finish
10 hdc install -r test.hap 重新安装HAP应用 [Info]App install path:D:\test.hap, queuesize:0, msg:install bundle successfully.<br>AppMod finish
11 hdc uninstall com.example.ohtest 卸载已安装应用 [Info]App uninstall path:, queuesize:0, msg:uninstall bundle successfully.<br>AppMod finish
12 hdc shell aa start -a com.example.ohtest.MainAbility -b com.example.ohtest 启动已安装应用<br>-a 后面是Ability的完整名字 <br>-b 后面是Bundle的完整名字 start ability successfully.
13 hdc hilog 查看日志 08-05 19:45:29.912...
14 hdc target mount 重新挂载/vendor和/system分区为可读写 Mount finish
15 hdc start -r 重新启动hdc服务进程 None
16 hdc kill 终止hdc服务进程 Kill server finish
17 hdc target boot 重启设备 None
18 hdc shell hilog -w start 开始保存日志到文件 Persist task [jobid:1] start successfully
18 hdc shell hilog -w stop 开始保存日志到文件 Persist task [jobid:1] stop successfully
19 hdc tconn 192.168.0.27:10111 TCP网络连接 None

四、hdc常用命令讲解,未尽命令使用hdc -h或者hdc --help查看

Sn Option Description Example
1 -t key 用于指定连接该指定设备识Key hdc -t *****(设备id) shell
2 -s socket 用于指定服务监听的socket配置 hdc -s ip:port
3 -h/help -v/version 用于显示hdc相关的帮助、版本信息 None
4 list targets[-v] 显示所有已经连接的目标设备列表,-v选项显示详细信息 hdc list targets
5 target mount 以读写模式挂载/vendor、/data等分区,因为安全性问题,需要挂在根目录或者/system分区请单独使用 'hdc_std shell mount -o rw,remount /'等命令 hdc target mount
6 smode [off] 授予后台服务进程root权限, 使用off参数取消授权 hdc smode
7 kill [-r] 终止hdc服务进程, -r选项会触发再次重启hdc server hdc kill
8 start [-r] 启动hdc服务进程, -r选项会触发重启hdc server hdc start
9 tconn host[:port][-remove] 通过【ip地址:端口号】来指定连接的设备<br>使用TCP模式连接设备,需在USB模式工作下使用 tmode tcp 切换至 TCP工作模式,或者在 <br>系统属性值中设置persist.hdc.mode属性值为tcp,如果需要监听固定 TCP端口需要再设置 <br>persist.hdc.port的端口号,反之则TCP监听端口随机 hdc tconn 192.168.0.100:10178
10 tmode usb 执行后设备端对应daemon进程重启,并首先选用usb连接方式 None
11 tmode port port-number 执行后设备端对应daemon进程重启,并优先使用网络方式连接设备,如果连接设备再选择usb连接 None
12 file send local remote 从host端发送文件至设备端 hdc file send E:\a.txt /data/local/tmp/a.txt
13 file recv [-a] remote local 从设备端拉出文件至本地host端 hdc file recv /data/local/tmp/a.txt ./a.txt
14 install [-r/-d/-g] package 安装OpenHarmony package hdc install E:\***.hap
15 uninstall [-k] package 卸载OpenHarmony应用 None
16 hilog 支持查看抓取hilog调试信息 hdc hilog
17 shell [command] 远程执行命令或进入交互命令环境 hdc shell

五、常见问题处理

  1. hdc list targets 查找不到设备 第一步, 检查PC上设备管理器中USB驱动是否正常,如果没有正常显示,卸载之前安装的驱动,然后重装驱动,或者更换USB线; 第二步, 检查PC上的hdc工具版本是否为最新,版本Ver: 1.1.2a 及以上; 第三步, 装完驱动后,重启PC和开发板; 第四步, 重启PC本地hdc服务:

hdc start -r 第五步,杀掉本地服务并重启PC侧hdc服务: hdc kill -r 第六步,如果不行,更换开发板。

  1. 从PC拷贝文件到开发板失败

hdc file send d:\ohtest.hap /system/ [Fail]Error opening file: read-only file system, path:/system//ohtest.hap 第一步,重新挂在目标目录 hdc shell mount -o rw,remount 第二步,可能目标目录只读,更换其他可读写目录尝试一下 hdc file send d:\ohtest.hap /data/ FileTransfer finish, Size:xxx time:86ms rate:xxxkB/s

  1. 从开发板拷贝文件到PC失败

hdc file recv /data/tmp/entry-debug-standard-ark-signed.hap d: [Fail]Error opening file: operation not permitted, path:d:\entry-debug-standard-ark-signed.hap 可能是磁盘根目录没有权限,建议建一个文件夹,然后拷贝到文件夹下 hdc file recv /data/tmp/entry-debug-standard-ark-signed.hap d:\recv FileTransfer finish, Size:71030 time:60ms rate:1183.83kB/s

六、补充

源代码目录 .\developtools\hdc,非必要不用编译。文中涉及的hdc工具和USB驱动从附件下载。 hdc_bin: hdc 工具包 DriverAssitant: RK3568 配套的USB驱动 Cmder.exe: 代替系统 cmd 控制台程序,可以分割多个窗口同时监听、交互感兴趣的内容。十分好用,因为安装包较大建议自行下载。

七、总结

OpenHarmony命令行工具hdc安装、应用指南详细阐述了hdc工具下载、安装、路径的环境配置和USB驱动安装。接下来完整给出了19条hdc命令用法及正确输出示意。最后列出典型的三种错误处理。

无用

©著作权归作者所有,转载或内容合作请联系作者

您尚未登录,无法参与评论,登录后可以:
参与开源共建问题交流
认同或收藏高质量问答
获取积分成为开源共建先驱

精彩评论1

诚迈_雨哥

沙发 发表于 2023-12-14 21:21:48
文中提及的驱动与工具下载

DriverAssitant.zip

1.1 MB, 下载次数: 64

USB驱动

hdc_bin.zip

1.37 MB, 下载次数: 70

hdc工具

Copyright   ©2023  OpenHarmony开发者论坛  京ICP备2020036654号-3 |技术支持 Discuz!

返回顶部