当前位置:   article > 正文

OpenHarmony命令行工具hdc安装应用指南_linux openharmony hdc

linux openharmony hdc

OpenHarmony命令行工具hdc安装应用指南

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调试线连接,开发板上运行开源系统主线版本。连接端口如蓝色线缆所示:

  • 安装USB驱动

DriverAssitant 是RK3568 开发板自带的 USB驱动。双击 DriverInstall.exe,选择驱动安装。

  • 设备管理器查看驱动是否安装成功

未连接USB先或者驱动未安装成功如图片左边所示;成功则如右边所示,会出现”hdc Device”。

3. hdc工具下载

  • 第一步,下载安装包

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

  • 第二步,解压缩任意一个

选择红框中的文件

  • 第三步,拷贝至D:\hdc_bin\目录下

注意:无须双击安装

4. hdc路径环境配置

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

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.

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

18

hdc shell hilog -w stop

开始保存日志到文件

Persist task [jobid:1] stop successfully

19

hdc tconn 192.168.0.27:10111

TCP网络连接

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

SnOptionDescriptionExample
1-t key用于指定连接该指定设备识Keyhdc -t *****(设备id) shell
2-s socket用于指定服务监听的socket配置hdc -s ip:port
3-h/help -v/version用于显示hdc相关的帮助、版本信息
4list targets[-v]显示所有已经连接的目标设备列表,-v选项显示详细信息hdc list targets
5target mount以读写模式挂载/vendor、/data等分区,因为安全性问题,需要挂在根目录或者/system分区请单独使用 'hdc_std shell mount -o rw,remount /'等命令hdc target mount
6smode [off]授予后台服务进程root权限, 使用off参数取消授权hdc smode
7kill [-r]终止hdc服务进程, -r选项会触发再次重启hdc serverhdc kill
8start [-r]启动hdc服务进程, -r选项会触发重启hdc serverhdc start
9tconn 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
10tmode usb执行后设备端对应daemon进程重启,并首先选用usb连接方式
11tmode port port-number执行后设备端对应daemon进程重启,并优先使用网络方式连接设备,如果连接设备再选择usb连接
12file send local remote从host端发送文件至设备端hdc file send E:\a.txt /data/local/tmp/a.txt
13file recv [-a] remote local从设备端拉出文件至本地host端hdc file recv /data/local/tmp/a.txt ./a.txt
14install [-r/-d/-g] package安装OpenHarmony packagehdc install E:\***.hap
15uninstall [-k] package卸载OpenHarmony应用
16hilog支持查看抓取hilog调试信息hdc hilog
17shell [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

第六步,如果不行,更换开发板。

2.从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

3.从开发板拷贝文件到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命令用法及正确输出示意。最后列出典型的三种错误处理。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/242713
推荐阅读
相关标签
  

闽ICP备14008679号