工具概述
hdc(OpenHarmony Device Connector)是为开发人员提供的用于设备连接调试的命令行工具,该工具需支持部署在 Windows/Linux/Mac 等系统上与 OpenHarmony 设备(或模拟器)进行连接调试通信。 简言之,hdc 是 OpenHarmony 提供的用于开发人员调试硬件、应用的命令行工具,用在电脑与开发板之间的交互。 适用于 OpenHarmony 应用、硬件开发及测试人员,是每个开发人员的必备、入门工具。
(简单理解为Android的adb,命令也有许多相似)
鸿蒙hdc命令
主要调试设备:dayu200
系统:OpenHarmony4.1.5.2
HDC环境:Mac或者windows的hdc环境配置可以网上搜搜。
查看网络状态
hdc shell ifconfig
设置时间
hdc shell date "2024-07-22 17:10:30”
设置性能模式,解决dayu200自动息屏
hdc shell power-shell setmode 602
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. AppMod finish |
| 10 | hdc install -r test.hap | 重新安装 HAP 应用 | [Info]App install path:D:\test.hap, queuesize:0, msg:install bundle successfully. AppMod finish |
| 11 | hdc uninstall com.example.ohtest | 卸载已安装应用 | [Info]App uninstall path:, queuesize:0, msg:uninstall bundle successfully. AppMod finish |
| 12 | hdc shell aa start -a com.example.ohtest.MainAbility -b com.example.ohtest | 启动已安装应用 -a 后面是 Ability 的完整名字 -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 |
| 19 | 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 地址:端口号】来指定连接的设备使用 TCP 模式连接设备,需在 USB 模式工作下使用 tmode tcp 切换至 TCP 工作模式,或者在系统属性值中设置persist.hdc.mode 属性值为 tcp,如果需要监听固定 TCP 端口需要再设置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 |