• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# hdc
2
3OpenHarmony Device Connector (hdc) is a command line tool used for debugging. You can use it on a Windows, Linux, or macOS system to interact with devices.
4
5hdc consists of three processes:
6
7**client**: the process running on the PC. This process is started when you run the hdc command and exits after the command is executed.
8
9**server**: the background server process running on the PC. It is used to manage data interaction between the **client** and **daemon** processes and discover devices.
10
11**daemon**: the daemon process running on the device. It is used to respond to the requests sent by **server**.
12
13The following figure shows the relationship.
14
15![hdc](figures/hdc_image_005.PNG)
16> **NOTE**
17>
18> When **client** is started, it checks whether **server** is running by default. If not, a new hdc program is started as the **server** and runs in the background.
19>
20> When **server** is running, it listens for port 8710 of the PC by default. You can set the system environment variable **OHOS_HDC_SERVER_PORT** to listen for a port.
21
22## Environment Setup
23
24The hdc tool is obtained from the **toolchains** directory of OpenHarmony SDK.
25
26### (Optional) Running the hdc Program on the CLI
27
28You can go to the **toolchains** directory of SDK through the CLI and run the hdc command in the directory for debugging.
29To facilitate the execution of the hdc program in the CLI, you can add the file path of the hdc program to the system environment variable that specifies the command search path.
30For example, add it to **Path** on Windows.
31
32### (Optional) Configuring the server Listening Port
33
34When the hdc server is started, it listens for port 8710 of the PC by default. The hdc client uses TCP to connect to the server through this port. If port 8710 of the PC has been used or you want to use another port, you can add the environment variable **OHOS_HDC_SERVER_PORT** to the system environment variable to listen for any unoccupied port when the server is started.
35For example, set **OHOS_HDC_SERVER_PORT** to **18710**.
36
37> **NOTE**
38>
39> After the environment variable is configured, close and restart the CLI and other software that uses OpenHarmony SDK.
40
41## hdc commands
42
43### Global Parameters
44
45Global parameters are the parameters that follow **hdc** when some hdc commands are run.
46For example, use the **-t** parameter to specify a device for command execution.
47
48   ```shell
49   hdc -t connect-key shell echo "Hello world"
50   ```
51
52| Parameter| Description|
53| -------- | -------- |
54| -t | Specifies a target device to connect. When one device is connected, this parameter is optional. When multiple devices are connected, it is mandatory.|
55| -l | (Optional) Specifies the log level when the device is running. The value ranges from 0 to 6. The default value is **3** (**LOG_INFO**).|
56| -s | (Optional) Specifies the IP and port for listening when the client connects to the server.|
57| -p | (Optional) Executes a client command without querying the server process.|
58| -m | (Optional) Starts the server process in the foreground.|
59
60### Commands
61| Command| Description|
62| -------- | -------- |
63| list targets | Displays all connected target devices.|
64| wait | Waits until the device is properly connected.|
65| tmode usb | This command is invalid and cannot be used to enable the USB connection channel. You need to enable it on the device setting page.|
66| tmode port | Enables the network connection channel of the device.|
67| tmode port close | Disables the network connection channel of the device.|
68| tconn | Specifies the device to connect based on the IP address and port number.|
69| shell | Executes a single command on the device.|
70| install | Installs an application.|
71| uninstall | Uninstalls a specified application.|
72| file send | Sends a local file to a remote device.|
73| file recv | Sends a file from a remote device to the local device.|
74| fport ls | Lists all port forwarding tasks.|
75| fport | Sets up a local port forwarding, which forwards data from a local port to a remote port.|
76| rport | Sets up a remote port forwarding, which forwards data from a remote port to a local port.|
77| fport rm | Deletes a port forwarding task.|
78| start | Starts the hdc server process.|
79| kill | Terminates the hdc server process.|
80| hilog | Obtains device log information.|
81| jpid | Displays the PIDs of all applications that have enabled JDWP on the device.|
82| track-jpid | Displays the PIDs and names of the applications that have enabled JDWP on the device in real time.|
83| target boot| Restarts the target device.|
84| <!--DelRow--> target mount | Mounts the system partition in read/write mode. (This command is unavailable for non-root devices.)|
85| <!--DelRow--> smode | Grants the **root** permission to the background hdc server running on the device. You can use the **-r** option to revoke the granted permission. (This command is unavailable for non-root devices.)|
86| keygen | Generates a new key pair.|
87| version | Displays the hdc version information. You can also run the **hdc -v** command to display the version information.|
88| checkserver | Obtains the version information about the client process and server process.|
89
90> **NOTE**
91>
92> Global parameters must be placed before commands.
93
94## Basic Commands
95
96Before using hdc, enable the USB debugging function on the device and connect the device to the PC using a USB cable.
97
98### Displaying Connected Devices
99
100   ```shell
101   hdc list targets
102   ```
103
104### Running the Shell command
105
106   ```shell
107   hdc shell echo "Hello world"
108   ```
109
110### Obtaining the Help Information
111
112| Command| Description|
113| -------- | -------- |
114| -h [verbose] | Displays the hdc help information. The optional parameter **verbose** can be used to display detailed help information.|
115| help | Displays the hdc help information.|
116
117Display the hdc help information.
118
119   ```shell
120   hdc -h [verbose]
121   hdc help
122   ```
123
124**Return value**
125| Return Value| Description|
126| -------- | -------- |
127| OpenHarmony device connector(HDC) ...<br>---------------------------------global commands:----------------------------------<br>-h/help [verbose]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Print hdc help, 'verbose' for more other cmds<br>..._(Detailed information is omitted here.)_| Help information for hdc commands.|
128
129**Usage**
130
131```shell
132hdc -h
133hdc help
134
135// Display the detailed help information.
136hdc -h verbose
137```
138
139### NOTE
140
141- If an exception occurs, run the **hdc kill -r** command to kill the hdc process and restart the hdc server.
142
143- If the **hdc list targets** command cannot obtain the device information, see [Failed to Identify the Target Device](#failed-to-identify-the-target-device).
144
145## Managing Device Connections
146
147### Displaying Devices
148
149Run the **list targets** command to display all connected target devices.
150You can add the **-v** parameter to display detailed device information.
151Run the following commands:
152
153```shell
154hdc list targets [-v]
155```
156
157**Return value**
158| Return Value| Description|
159| -------- | -------- |
160| Device ID list| List of connected device IDs. The ID is the value of **connect-key** used in the **-t** parameter.|
161| [Empty] | No device is found.|
162
163**Usage**
164
165```shell
166hdc list targets
167hdc list targets -v
168```
169
170### Connecting to the Specified Target Device
171
172When a single device is connected, you do not need to specify the device ID when running the command.
173When multiple devices are connected, use the **-t** parameter to specify the target device ID each time you run the command.
174
175   ```shell
176   hdc -t [connect-key] [command]
177   ```
178
179   **Parameters**
180   | Name| Description|
181   | -------- | -------- |
182   | connect-key| Device ID, which is the return value of the **hdc list targets** command.|
183   | command | Command to be executed.|
184
185   > **NOTE**
186   >
187   > The *connect-key* uniquely identifies a device. If the device is connected over the network, the *connect-key* is the IP address and port number. If the device is connected through USB, the *connect-key* is the USB SN.
188
189   **Return value**
190   | Return Value| Description|
191   | -------- | -------- |
192   | Command output| Command execution result, which may vary with the command.|
193   | [Fail]Not match target founded, check connect-key please | No device matches the *connect-key*.|
194   | [Fail]Device not founded or connected | The device is not found or connected.|
195   | [Fail]ExecuteCommand need connect-key? please confirm a device by help info | You must specify one device if there are multiple devices available.|
196   | Unknown operation command... | The command is not supported.|
197
198   > **NOTE**
199   >
200   > The error messages will be optimized in the future. Do not use them to determine the result of the automatic script or program.
201
202   **Usage**
203
204   This option must be used with a command. The following uses the **shell** command as an example.
205
206   ```shell
207   hdc list targets  // Display connect-key of all connected devices.
208   hdc -t [connect-key] shell // Replace connect-key with the specified device ID.
209   ```
210
211### Waiting for Device Connection
212
213Run the following commands:
214
215   ```shell
216   hdc wait // Wait for the device to connect.
217   hdc -t connect-key wait // Wait for the specified device to connect. Replace connect-key with the specified device ID.
218   ```
219
220   **Return value**
221   | Return Value| Description|
222   | -------- | -------- |
223   | None| The **hdc wait** command ends when a properly connected device is identified.|
224
225   **Usage**
226
227   ```shell
228   hdc wait
229   hdc -t connect-key wait
230   ```
231
232### Common Connections
233
234#### USB Connection
235
236- Checking the environment
237
238| Item| Normal| Exception Handling|
239| -------- | -------- | -------- |
240| USB debugging| USB debugging is enabled.| If the USB debugging mode is not automatically enabled, restart the device.|
241| USB data cable connection| The PC used for debugging is connected to the device USB port using a USB cable.| If you use a USB cable with low bandwidth and no data communication function, the device may fail to be identified. You are advised to use an officially recommended USB cable.|
242| USB port| A USB port on the mainboard (USB port on the rear panel of a desktop computer or USB port on a laptop computer) is used.| If you use a conversion adapter, docking station, or USB port on the front panel of a desktop computer, issues such as low bandwidth and USB sync problems may occur, which results in frequent disconnections. Therefore, direct connection between the PC and the device is recommended.|
243| hdc environment variable| The help information is displayed after the **hdc -h** command is executed.| For details, see [Environment Setup](#environment-setup).|
244| Driver| After the device is connected via hdc, **HDC Device** or **HDC Interface** is displayed in **Device Manager**.| For details, see [Failed to Identify the Target Device](#failed-to-identify-the-target-device).|
245
246- Procedure
247
2481. Connect the PC to the device through a USB port.
249
2502. Check the connection.
251
252   ```shell
253   hdc list targets
254   ```
255
256   If the corresponding device ID is returned, the USB connection is successful.
257
2583. When the device is found, run the related commands to interact with the device. If you want to perform USB command operations without the device ID, ensure that the device is not in TCP connection mode (the device information displayed by running the **hdc list targets** command does not contain **IP:port**) and directly connect to the device. For example:
259
260   ```shell
261   hdc shell
262   ```
263
264#### TCP Connection
265
266   > **NOTE**
267   >
268   > The TCP debugging function is not stable. Exercise caution when using this function for production.
269
270- Checking the environment
271
272| Item| Normal| Exception Handling|
273| -------- | -------- | -------- |
274| Network connection| The PC and the device are on the same network.| Connect the PC and device to the same Wi-Fi network or enable the Wi-Fi hotspot on your device.|
275| Network Status| Use **telnet IP:port** to check that the network connection between the PC and the device is normal.| Connect the PC and the device over a stable network.|
276| hdc environment variable| The help information is displayed after the **hdc -h** command is executed.| For details, see [Environment Setup](#environment-setup).|
277
278- Procedure
279
2801. Enable network debugging on the device setting page.
281
2822. Record the port number displayed on the device as **PORT** for TCP connection.
283
2843. Run the following command to connect to the device through TCP (you need to know the device IP address and enabled port number):
285
286   ```shell
287   hdc tconn IP:PORT
288   ```
289   You can obtain the IP address from the device settings. The port number is displayed in the previous step.
290
2914. Check the connection.
292
293   ```shell
294   hdc list targets
295   ```
296
297   If the return value is in the *IP:PORT* format, the connection is successful.
298
2995. To disable the TCP connection mode, disable network debugging on the device.
300
301#### Remote Connection
302
303In the remote connection scenario, the client remotely connects to the server through the network. The client and server run on different PCs, and the server connects to the device.
304The following figure shows the remote connection.
305
306![Remote connection structure](figures/hdc_image_004.PNG)
307
308The hdc client runs on PC1, and the hdc server runs on PC2, which is connected to the device.
309
310- Connection command
311
312   | Command| Description|
313   | -------- | -------- |
314   | -s | Specifies the IP address and port number of the current server process to listen for.|
315
316   Use the **-s** parameter to specify the IP address and port number of the server. The setting is valid only when the current command is executed.
317
318   ```shell
319   hdc -s [ip]:[port] [command]
320   ```
321
322   **Parameters**
323   | Parameter| Description|
324   | -------- | -------- |
325   | ip | IP address to listen for. Both IPv4 and IPv6 addresses are supported.|
326   | port | Port to listen for. The value ranges from 1 to 65535.|
327   | command | Command to be executed.|
328
329   **Return value**
330   | Return Value| Description|
331   | -------- | -------- |
332   | Connect server failed | Fails to connect to the server.|
333   | -s content port incorrect. | The port number is out of range (1 to 65535).|
334
335   **Usage**
336
337   ```shell
338   # Run the command to obtain the device information in the server process of 127.0.0.1:8710:
339   hdc -s 127.0.0.1:8710 list targets
340   ```
341
342   > **NOTE**
343   >
344   > If the **-s** parameter is used to specify a server port, the system ignores the port set in the **OHOS_HDC_SERVER_PORT** environment variable.
345
346- Procedure
347
348   1. Configure the server
349
350   Connect the server to the device using a USB cable and run the following commands:
351
352   ```shell
353   hdc kill          // Terminate the local hdc server.
354   hdc -s IP:8710 -m // Enable the hdc server for network forwarding.
355                     // In the command, IP indicates the IP address of the server. To query the IP address, you can run the **ipconfig** command on Windows and run the **ifconfig** command on Unix.
356                     // 8710 is the default port number. You can also set it to another port number, for example, 18710.
357                     // After startup, the server prints logs.
358   ```
359
360   2. Connect to the client
361
362   Ensure that the client can connect to the server IP address, and then run the following command:
363
364   ```shell
365   hdc -s IP:8710 [command] // IP indicates the IP address of the server, and 8710 indicates the port number set when the server is started in step 1.
366                           // If the port number changes, change the port number accordingly.
367                           // and command can be any available hdc command, for example, list targets.
368   ```
369
370### Switching Between USB Debugging and Network Debugging
371
372The following table lists the commands for switching the connection mode.
373
374You are advised to enable or disable the USB debugging and network debugging on the device.
375
376| Command| Description|
377| -------- | -------- |
378| tmode usb | This command is invalid and cannot be used to enable the USB connection channel. You need to enable it on the device setting page.|
379| tmode port [port-number] | Enables the network connection channel of the device. Then the daemon process on the device restarts, and the USB connection is interrupted. You need to reconnect the device.|
380| tmode port close | Disables the network connection channel of the device. Then the daemon process on the device restarts, and the USB connection is interrupted. You need to reconnect the device.|
381| tconn [IP]:[port] [-remove] | Specifies a connection to a device in *IP address: port number* format. Use the **-remove** option to disconnect from the specified device.|
382
3831. Enable the network connection of the device.
384
385   ```shell
386   hdc tmode port [port-number]
387   ```
388
389   **Parameters**
390   | Parameter| Description|
391   | -------- | -------- |
392   | port-number | Port number of the connection. The value ranges from 1 to 65535.|
393
394   **Return value**
395   | Return Value| Description|
396   | -------- | -------- |
397   | Set device run mode successful. | The network connection channel is enabled successfully.|
398   | [Fail]ExecuteCommand need connect-key | Failed to enable the network connection channel because no device exists in the list. |
399   | [Fail]Incorrect port range | The port number is out of range (1 to 65535).|
400
401   **Usage**
402
403   ```shell
404   hdc tmode port 1234
405   ```
406
407   > **NOTE**
408   >
409   > Before changing the connection mode, ensure that the remote device and the local PC are on the same network and the PC can ping the IP address of the remote device.
410   >
411   > Otherwise, do not run this command.
412
413   > **NOTE**
414   >
415   > After the command is executed, the remote daemon process exits and restarts, and the USB connection is disconnected. You need to reconnect the USB connection.
416
4172. Disable the network connection channel of the device.
418
419   ```shell
420   hdc tmode port close
421   ```
422
423   **Return value**
424   | Return Value| Description|
425   | -------- | -------- |
426   | [Fail]ExecuteCommand need connect-key | Failed to disable the network connection channel because no device exists in the list.|
427
428   **Usage**
429
430   ```shell
431   hdc tmode port close
432   ```
433   > **NOTE**
434   > After the command is executed, the remote daemon process exits and restarts, and the USB connection is disconnected. You need to reconnect the USB connection.
435
4363. Connect to the specified device through TCP.
437
438   ```shell
439   hdc tconn [IP]:[port] [-remove]
440   ```
441
442   **Parameters**
443   | Parameter| Description|
444   | -------- | -------- |
445   | [IP]:[port]  | IP address and port number of the device.|
446   | -remove | An optional parameter used to disconnect a specified device.|
447
448   **Return value**
449   | Return Value| Description|
450   | -------- | -------- |
451   | Connect OK | Device connected.|
452   | [Info]Target is connected, repeat operation| The device is already connected.|
453   | [Fail]Connect failed | Failed to connect the specified device.|
454
455   **Usage**
456
457   ```shell
458   hdc tconn 192.168.0.1:8888
459   hdc tconn 192.168.0.1:8888 -remove  // Disconnect from the specified device.
460   ```
461
462## Running the Interactive Command
463
464Run the following commands:
465
466   ```shell
467   hdc shell [-b bundlename] [command]
468   ```
469
470   **Parameters**
471   | Parameter| Description|
472   | -------- | -------- |
473   | [-b _bundlename_] | The bundle name of a debug application. The command is executed in non-interactive mode in the data directory of the debug application.<br>Currently, this parameter can be used only in non-interactive mode, and the **command** parameter must be specified to enter an interactive shell session.<br>Otherwise, commands are executed in the system root directory by default.|
474   | [command] | A single command to execute on the device. The command varies depending on the system type or version. You can run the **hdc shell ls /system/bin** command to obtain the supported command list. Currently, many commands are provided by [toybox](../tools/toybox.md). You can run the **hdc shell toybox --help** command to obtain the help information.<br>If this parameter is not specified, hdc starts an interactive shell session, in which you can enter commands such as **ls**, **cd**, and **pwd** at the command prompt.|
475
476   **Return value**
477   | Return Value| Description|
478   | -------- | -------- |
479   | Command execution result| Execution result of the command. For details, see the corresponding command output.|
480   | /bin/sh: XXX : inaccessible or not found | The specified command is not supported.|
481   | [Fail]Error information| The execution fails. For details, see [hdc Error Codes](#hdc-error-codes).|
482
483   **Usage**
484
485   ```shell
486   # Enter the interactive mode to run a command.
487   hdc shell
488
489   # Run the command in non-interactive mode.
490   hdc shell ps -ef
491
492   # Obtain the help information.
493   hdc shell help -a
494
495   # Specify the bundle name of an application to run the command in non-interactive mode in its data directory. The **touch**, **rm**, **ls**, **stat**, **cat** and **mkdir** commands are supported.
496   hdc shell -b com.example.myapplication ls data/storage/el2/base/
497   ```
498
499   > **NOTE**
500   >
501   > To use the **\[-b _bundlename_]** parameter, ensure that the installed application to be specified is an application built in debug mode. For details about how to build an application in debug mode, see [Building a HAR in Debug Mode](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/ide-hvigor-build-har-V5#section197792874110).
502
503## Managing Applications
504
505| Command| Description|
506| -------- | -------- |
507| install _src_ | Installs an application.|
508| uninstall _packageName_ | Uninstalls an application.|
509
5101. Install an app.
511
512   ```shell
513   hdc install [-r|-s] src
514   ```
515
516   **Parameters**
517   | Name| Description|
518   | -------- | -------- |
519   | src| Installation package name.|
520   | -r | Replaces the existing app (.hap).|
521   | -s | Install a shared package (.hsp).|
522
523   **Return value**
524   | Return Value| Description|
525   | -------- | -------- |
526   | AppMod finish | The installation is successful.|
527   | Error information| The installation fails.|
528
529   **Usage**
530
531   For example, install **example.hap**.
532
533   ```shell
534   hdc install E:\example.hap
535   ```
536
5372. Uninstall the app.
538
539   ```shell
540   hdc uninstall [-k|-s] packageName
541   ```
542
543   **Parameters**
544   | Name| Description|
545   | -------- | -------- |
546   | packageName | Application installation package.|
547   | -k | Used to retain **/data** and **/cache**.|
548   | -s | Used to uninstall a shared package.|
549
550   **Return value**
551   | Return Value| Description|
552   | -------- | -------- |
553   | AppMod finish | The uninstallation is successful.|
554   | Error information| The uninstallation fails.|
555
556   **Usage**
557
558   For example, uninstall **com.example.hello**.
559
560   ```shell
561   hdc uninstall com.example.hello
562   ```
563
564## Transferring Files
565
566| Command| Description|
567| -------- | -------- |
568| file send _localpath remotepath_ | Sends a local file to a remote device.|
569| file recv _remotepath localpath_ | Sends a file from a remote device to the local device.|
570
5711. Send a local file to a remote device.
572
573   ```shell
574   hdc file send [-a|-sync|-z|-m|-b bundlename] localpath remotepath
575   ```
576
577   **Parameters**
578   | Name| Description|
579   | -------- | -------- |
580   | _localpath_ | Path of the file to send on the local device.|
581   | _remotepath_ | Destination path on the remote device.|
582   | -a | Used to retain the file timestamp.|
583   | -sync | Used to transfer only the files whose **mtime** is updated.|
584   | -z | Used to compress and transmit files in LZ4 format. This parameter is unavailable.|
585   | -m | Used to synchronize the DAC permission, UID, GID, and MAC permission during file transfer.|
586   | -b | Used to transfer files in the application data directory of the specified debug application process.|
587   | _bundlename_ | Bundle name of the debug application process.|
588
589   **Return value**
590
591   A success message is displayed if the file is sent successfully. Error information is displayed if the file fails to be sent.
592
593   **Usage**
594
595   ```shell
596   hdc file send E:\example.txt /data/local/tmp/example.txt
597   hdc file send -b com.example.myapplication a.txt data/storage/el2/base/b.txt
598   ```
599
600   > **NOTE**
601   >
602   > In the **hdc file send -b com.example.myapplication a.txt data/storage/el2/base/b.txt** command, the **-b** parameter is specified to transfer the **a.txt** file in the current local directory to the relative path **data/storage/el2/base/** of the **com.example.myapplication** application data directory and rename the file to **b.txt**.
603   >
604   > To use the **\[-b _bundlename_]** parameter, ensure that the installed application to be specified is an application built in debug mode. For details about how to build an application in debug mode, see [Building a HAR in Debug Mode](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/ide-hvigor-build-har-V5#section197792874110).
605
6062. Send a file from a remote device to the local device.
607
608   ```shell
609   hdc file recv [-a|-sync|-z|-m|-b bundlename] remotepath localpath
610   ```
611
612   **Parameters**
613   | Name| Description|
614   | -------- | -------- |
615   | _localpath_ | Destination path on the local device.|
616   | _remotepath_ | Path of the file to send on the remote device.|
617   | -a | Used to retain the file timestamp.|
618   | -sync | Used to transfer only the files whose **mtime** is updated.|
619   | -z | Used to compress and transmit files in LZ4 format. This parameter is unavailable.|
620   | -m | Used to synchronize the DAC permission, UID, GID, and MAC permission during file transfer.|
621   | -b | Used to transfer files in the application data directory of the specified debug application process.|
622   | _bundlename_ | Bundle name of the debug application process.|
623
624   **Return value**
625
626   A success message is displayed if the file is received successfully. Error information is displayed if the file fails to be received.
627
628   **Usage**
629
630   ```shell
631   hdc file recv  /data/local/tmp/a.txt   ./a.txt
632   hdc file recv -b com.example.myapplication data/storage/el2/base/b.txt   a.txt
633   ```
634
635   > **NOTE**
636   >
637   > In the **hdc file recv -b com.example.myapplication data/storage/el2/base/b.txt a.txt** command, the **-b** parameter is specified to transfer the **b.txt** file in the relative path **data/storage/el2/base/** of the **com.example.myapplication** application data directory to the current local directory and rename the file to **a.txt**.
638   >
639   > To use the **\[-b _bundlename_]** parameter, ensure that the installed application to be specified is an application built in debug mode. For details about how to build an application in debug mode, see [Building a HAR in Debug Mode](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/ide-hvigor-build-har-V5#section197792874110).
640
641## Port Forwarding
642
643| Command| Description|
644| -------- | -------- |
645| fport ls | Lists all port forwarding tasks.|
646| fport _localnode remotenode_ | Sets up a local port forwarding, which forwards data from a local port to a remote port.|
647| rport _remotenode localnode_ | Sets up a remote port forwarding, which forwards data from a remote port to a local port.|
648| fport rm _taskstr_ | Deletes a port forwarding task.|
649
650Port forwarding type supported by the PC: TCP.
651
652Port forwarding type supported by the device: TCP, DEV, localabstract, localfilesystem, JDWP, ark.
653
6541. List all port forwarding tasks.
655
656   ```shell
657   hdc fport ls
658   ```
659
660   **Return value**
661   | Return Value| Description|
662   | -------- | -------- |
663   | tcp:1234 tcp:1080 [Forward] | Local port forwarding.|
664   | tcp:2080 tcp:2345 [Reverse] | Remote port forwarding.|
665   | [empty] | No port forwarding.|
666
667   **Usage**
668
669   ```shell
670   hdc fport ls
671   ```
672
6732. Set up a local port forwarding, which forwards data from a local port to a remote port.
674
675   ```shell
676   hdc fport localnode remotenode
677   ```
678
679   **Return value**
680   | Return Value| Description|
681   | -------- | -------- |
682   | Forwardport result:OK | The port forwarding is set up properly.|
683   | [Fail]Incorrect forward command | Failed to set up the port forwarding due to parameter errors.|
684   | [Fail]TCP Port listen failed at XXXX | Failed to set up the port forwarding because the local port is in use.|
685
686   **Usage**
687
688   ```shell
689   hdc fport tcp:1234 tcp:1080
690   ```
691
6923. Set up a remote port forwarding, which forwards data from a remote port to a local port.
693
694   ```shell
695   hdc rport remotenode localnode
696   ```
697
698   **Return value**
699   | Return Value| Description|
700   | -------- | -------- |
701   | Forwardport result:OK | The port forwarding is set up properly.|
702   | [Fail]Incorrect forward command | Failed to set up the port forwarding due to parameter errors.|
703   | [Fail]TCP Port listen failed at XXXX | Failed to set up the port forwarding because the local port is in use.|
704
705   **Usage**
706
707   ```shell
708   hdc rport tcp:1234 tcp:1080
709   ```
7104. Delete a specified port forwarding task.
711
712   ```shell
713   hdc fport rm taskstr
714   ```
715
716   **Parameters**
717   | Parameter| Description|
718   | -------- | -------- |
719   | _taskstr_ | Port forwarding task, in the format of **tcp:XXXX tcp:XXXX**.|
720
721   **Return value**
722   | Return Value| Description|
723   | -------- | -------- |
724   | Remove forward ruler success, ruler:tcp:XXXX tcp:XXXX | The port forwarding is removed successfully.|
725   | [Fail]Remove forward ruler failed, ruler is not exist tcp:XXXX tcp:XXXX | Failed to remove the port forwarding because the specified forwarding does not exist.|
726
727   **Usage**
728
729   ```shell
730   hdc fport rm tcp:1234 tcp:1080
731   ```
732
733## Managing Server Processes
734
735| Command| Description|
736| -------- | -------- |
737| start [-r] | Starts the hdc process. You can use the **-r** option to restart the process.|
738| kill [-r] | Terminates the hdc process. You can use the **-r** option to restart the process.|
739| -p | Executes a client command without querying the server process.|
740| -m | Starts a server process in the foreground.|
741
742
7431. Start the hdc server.
744
745   ```shell
746   hdc start [-r]
747   ```
748
749   **Return value**
750   | Return Value| Description|
751   | -------- | -------- |
752   | hdc start server, listening: _::ffff:127.0.0.1:8710_ | The server is started and the IP address and port number are displayed.|
753   | Start server finish | The server is started successfully.|
754   | hdc server process already exists | The server already exists.|
755   | Kill server finish | The server is restarted after the original server is terminated.|
756   | [Fail]Error information| Failed to start the server process.|
757
758   **Usage**
759
760   ```shell
761   hdc start
762   hdc start -r // Restart the server.
763   ```
764
765   > **NOTE**
766   >
767   > When a hdc server is started and the system does not detect any running server, set the log level in the following sequence: If the **-l** parameter is specified and the **OHOS_HDC_LOG_LEVEL** environment variable is configured, use the log level configured by the environment variable. If only the **-l** parameter is specified, use the log level configured by this parameter. If both of them are not specified, the server starts with the default log level **LOG_INFO**.
768
7692. Terminate the hdc server.
770
771   ```shell
772   hdc kill [-r]
773   ```
774
775   **Return value**
776   | Return Value| Description|
777   | -------- | -------- |
778   | Kill server finish | The server is terminated successfully.|
779   | [Fail]Error information| Failed to terminate the server.|
780
781   **Usage**
782
783   ```shell
784   hdc kill
785   hdc kill -r // Restart and terminate the server process.
786   ```
787
7883. Execute a client command without querying the server.
789
790   ```shell
791   hdc -p [command]
792   ```
793
794   **Parameters**
795   | Parameter| Description|
796   | -------- | -------- |
797   | command | Command to be executed.|
798
799   **Return value**
800   | Return Value| Description|
801   | -------- | -------- |
802   | Connect server failed | Fails to connect to the server.|
803
804   **Usage**
805
806   ```shell
807   # Start a background server.
808   hdc start
809   # Execute the command directly without querying the server.
810   hdc -p list targets
811   ```
812
813   > **NOTE**
814   >
815   > When a command is executed without the **-p** parameter specified, the client first checks whether a server is running locally. If the system does not detect a running server process, the client automatically starts a server process and sets up a connection to transfer commands. If the system detects a running server process, the client directly connects to the server process and transfers commands.
816
8174. Start the server process in the foreground.
818
819   ```shell
820   hdc -m
821   ```
822
823   **Return value**
824   | Return Value| Description|
825   | -------- | -------- |
826   | Initial failed | The server process fails to be initialized.|
827   | [I][_1970-01-01 00:00:00.000_][_abcd_][_session.cpp:25_] _Program running. Ver: X.X.Xa Pid:12345_ | Logs of the corresponding level are printed to display the activity status of the server.|
828
829   **Usage**
830
831   ```shell
832   # Start a server process with the IP address and port number specified.
833   hdc -s 127.0.0.1:8710 -m
834   ```
835
836   > **NOTE**
837   >
838   > 1. When using the **-m** parameter, you can add the **-s** parameter to specify the IP address and port number to be listened. If no IP address and port number are specified using the **-s** parameter and the environment variable **OHOS_HDC_SERVER_PORT** is not set, the system uses the default IP address and port number **127.0.0.1:8710**.
839   > 2. If the server process is started in the foreground, the default log output level is **LOG_DEBUG**. You can use the **-l** parameter to change the log level.
840   > 3. Only one server process instance can run at a time. If a background server process is running, a new server process instance cannot be started on the foreground.
841
842## Operating the Device
843
844| Command| Description|
845| -------- | -------- |
846| hilog [-h] | Displays the log information of the device. You can run the **hdc hilog -h** command to obtain the supported parameters. |
847| jpid | Displays the PIDs of all applications that have enabled JDWP on the device.|
848| track-jpid [-a\|-p]  | Displays the PID and name of the application for which JDWP is enabled on the device in real time. If no parameter is specified, only the processes of the **debug** application are displayed. If the **-a** parameter is specified, the processes of the **debug** and **release** applications are displayed. If the **-p** parameter is specified, the **debug** and **release** labels are not displayed.|
849| target boot [-bootloader\|-recovery] | Restarts the target device. You can use the **-bootloader** option to enter the fastboot mode and the **-recovery** option to enter the recovery mode.|
850| target boot [MODE] | Restart the target device to enter the corresponding mode. **MODE** is an option supported by **reboot** in the **/bin/begetctl** command.|
851| <!--DelRow--> target mount | Mounts the system partition in read/write mode. (This command is supported after the device has required the root permission.)|
852| <!--DelRow--> smode [-r] | Grants the root permission to the hdc background server process on the device. You can use the **-r** parameter to cancel the permission. (This command is supported after the device has required the root permission.)|
853
8541. Display the log information of the device.
855
856   ```shell
857   hdc hilog [-h]
858   ```
859
860   **Parameters**
861   | Parameter| Description|
862   | -------- | -------- |
863   | [-h] | Parameters supported by HiLog. You can run the **hdc hilog -h** command to obtain the parameter list.|
864
865   **Return value**
866   | Return Value| Description|
867   | -------- | -------- |
868   | Returned information| Log information obtained.|
869
870   **Usage**
871
872   ```shell
873   hdc hilog
874   ```
875
8762. Display the PIDs of all processes that enable JDWP.
877
878   ```shell
879   hdc jpid
880   ```
881
882   **Return value**
883   | Return Value| Description|
884   | -------- | -------- |
885   | PID list| PIDs of the applications that enable JDWP.|
886   | [empty] | No process enables JDWP.|
887
888   **Usage**
889
890   ```shell
891   hdc jpid
892   ```
893
8943. Display the PIDs and application names of the processes that enable JDWP on the device in real time.
895
896   ```shell
897   track-jpid [-a|-p]
898   ```
899
900   **Parameters**
901   | Parameter| Description|
902   | -------- | -------- |
903   | Not specified| Used to display only the PIDs, bundle names, and process names of **debug** applications.|
904   | -a | Used to display the PIDs, bundle names, and process names of the **debug** and **release** applications. |
905   | -p | Used to display the PIDs, bundle names, and process names of the **debug** and **release** applications, but does not display the **debug** and **release** labels.|
906
907   **Return value**
908   | Return Value| Description|
909   | -------- | -------- |
910   | PIDs and bundle/process name list| - |
911   | [empty] | If no parameter is specified, no process of the debug application enables JDWP. If the **-a** or **-p** parameter is specified, no process enables JDWP.|
912
913   **Usage**
914
915   ```shell
916   hdc track-jpid
917   ```
918
9194. Restart the target device.
920
921   ```shell
922   target boot [-bootloader|-recovery]
923   target boot [MODE]
924   ```
925
926   **Parameters**
927   | Name| Description|
928   | -------- | -------- |
929   | Not specified| Used to restart a device.|
930   | -bootloader| Used to restart a device to enter the **fastboot** mode.|
931   | -recovery | Used to restart a device to enter the **recovery** mode.|
932   | MODE | Used to restart a device to enter the **MODE** mode. **MODE** is a parameter supported by **reboot** in the **/bin/begetctl** command.<br> For details, run the **hdc shell "/bin/begetctl -h \| grep reboot"** command.|  |
933
934   **Usage**
935
936   ```shell
937   hdc target boot -bootloader // Restart the device to enter the fastboot mode.
938   hdc target boot -recovery // Restart the device to enter the recovery mode.
939   hdc target boot shutdown // Shut down the device.
940   ```
941
942<!--Del-->
9435. Mount the system partition in read/write mode.
944
945   ```shell
946   hdc target mount
947   ```
948
949   **Return value**
950   | Return Value| Description|
951   | -------- | -------- |
952   | Mount finish | Mounting succeeded.|
953   | [Fail]Mount failed | Mounting failed.|
954
955   **Usage**
956
957   ```shell
958   hdc target mount
959   ```
960
961   > **NOTE**
962   >
963   > This command is supported only after the device has required the root permission. Exercise caution when running this command.
964
9656. Grant the **root** permission to the background hdc server running on the device.
966
967   ```shell
968   hdc smode [-r]
969   ```
970
971   **Return value**
972   | Return Value| Description|
973   | -------- | -------- |
974   | No return value| Permission granted.|
975   | [Fail]Error information| Failed to grant the permission.|
976
977   **Usage**
978
979   ```shell
980   hdc smode
981   hdc smode -r  // Revoke the root permission.
982   ```
983
984   > **NOTE**
985   >
986   > This command is supported only after the device has required the **root** permission.
987
988<!--DelEnd-->
989
990## Security Command
991
992| Command| Description|
993| -------- | -------- |
994| keygen FILE | Generates a new key pair and save the private key and public key to **FILE** and **FILE.pub** respectively. The file name **FILE** can be customized.|
995
9961. Generate a new key pair.
997
998   ```shell
999   hdc keygen FILE
1000   ```
1001
1002   **Parameters**
1003   | Parameter| Description|
1004   | -------- | -------- |
1005   | FILE | Custom file name.|
1006
1007   **Usage**
1008
1009   ```shell
1010   hdc keygen key // Generate the key and key.pub files in the current directory.
1011   ```
1012
1013## Obtaining the Version Number
1014
1015| Command| Description|
1016| -------- | -------- |
1017| -v/version | Displays hdc version information.|
1018| checkserver | Obtains the client and server process versions.|
1019
10201. Display hdc version information.
1021
1022   ```shell
1023   hdc -v/version
1024   ```
1025
1026   **Return value**
1027   | Return Value| Description|
1028   | -------- | -------- |
1029   | Ver: X.X.Xa | hdc (SDK) version information.|
1030
1031   **Usage**
1032
1033   ```shell
1034   hdc -v or hdc version
1035   ```
1036
10372. Obtain the client and server process versions.
1038
1039   ```shell
1040   hdc checkserver
1041   ```
1042
1043   **Return value**
1044   | Return Value| Description|
1045   | -------- | -------- |
1046   | Client version: Ver: X.X.Xa, Server version: Ver: X.X.Xa | The client and server versions.|
1047
1048   **Usage**
1049
1050   ```shell
1051   hdc checkserver
1052   ```
1053
1054## hdc Debugging Logs
1055
1056### Server Logs
1057
1058#### Log Level
1059
1060Specify the hdc log level. The default value is **LOG_INFO**.
1061
1062   ```shell
1063   hdc -l [level] [command]
1064   ```
1065
1066   **Parameters**
1067   | Parameter| Description|
1068   | -------- | -------- |
1069   | [level] | Log level.<br>0: LOG_OFF<br>1: LOG_FATAL<br>2: LOG_WARN<br>3: LOG_INFO<br>4: LOG_DEBUG<br>5: LOG_ALL<br>6: LOG_LIBUSB|
1070   | command | Command to be executed.|
1071
1072   > **NOTE**
1073   >
1074   > 1. When the log level is set to 6 (**LOG_LIBUSB**), incremental logs related to libusb are generated. The incremental logs are detailed and contain a large amount of data, which helps accurately diagnose USB-related exceptions in server processes. USB-related operations are mainly performed by server processes. Therefore, incremental logs are available only for server processes. Accordingly, the client logs almost do not contain incremental log information.
1075   > 2. You can change only the log levels of the current client and server processes.
1076
1077   **Return value**
1078   | Return Value| Description|
1079   | -------- | -------- |
1080   | Command output| Command execution result, which may vary with the command.|
1081   | Log information| Logs of the specified level.|
1082
1083   **Usage**
1084
1085   Run the **shell ls** command with the log level specified to **LOG_DEBUG**.
1086
1087   ```shell
1088   hdc -l 5 shell ls
1089   ```
1090
1091   Run the **-m** command with the log level specify to **LOG_LIBUSB**.
1092
1093   ```shell
1094   hdc kill && hdc -l 6 -m
1095   ```
1096
1097   > **NOTE**
1098   > The **-m** parameter is used to start the server process in the foreground. You can directly view the foreground log output and press **Ctrl+C** to exit the process.
1099
1100   Start the server process in the background with the log level set to **LOG_LIBUSB**.
1101
1102   ```shell
1103   hdc kill && hdc -l 6 start
1104   ```
1105
1106   > **NOTE**
1107   > When the server process is started in the background, you can view the log output in **hdc.log**. For details about the log path, see **Obtaining Logs**.
1108
1109#### Obtaining Logs
1110
1111Obtain server logs.
1112
1113```shell
1114hdc kill
1115hdc -l5 start
1116```
1117
1118The collected logs are stored in the following path.
1119
1120| OS| Path| Remarks|
1121| -------- | -------- | -------- |
1122| Windows | %temp% | Example: **C:\Users\Username\AppData\Local\Temp**.<br>Replace *Username* with the actual one.|
1123| Linux | /tmp | - |
1124| macOS| $TMPDIR | - |
1125
1126Log-related environment variables
1127
1128| Environment Variable            | Default Value| Description                            |
1129|--------------------|-----|--------------------------------|
1130| OHOS_HDC_LOG_LEVEL | 5   | The log level of the server process.<br>For details, see [Server Logs](#server-logs). |
1131
1132Configure environment variables as follows:
1133
1134The following shows how to set the **OHOS_HDC_LOG_LEVEL** environment variable to **5**.
1135
1136| OS| Configuration Method|
1137|---|---|
1138| Windows  | Choose **This PC >Properties >Advanced system settings >Advanced >Environment Variables**, add the environment variable **OHOS_HDC_LOG_LEVEL**, and set its value to **5**. After the configuration is complete, click **OK**. Restart the CLI or other software that uses OpenHarmony SDK for the new environment variable to take effect. |
1139| Linux  | Add **export OHOS_HDC_LOG_LEVEL=5** to the end of the **~/.bash_profile** file, save the file, and run the **source ~/.bash_profile** command for the current environment variable to take effect.|
1140| macOS | Add **export OHOS_HDC_LOG_LEVEL=5** to the end of the **~/.zshrc** file, save the file, and run the **source ~/.zshrc** command for the current environment variable to take effect. Restart the CLI or other software that uses OpenHarmony SDK for the new environment variable to take effect.|
1141
1142### Device Logs
1143
1144Enable HiLog to obtain the corresponding logs.
1145
1146```shell
1147hdc shell hilog -w start                             // Enable the function of storing HiLog logs.
1148hdc shell ls /data/log/hilog                     // View the stored HiLog logs.
1149hdc file recv /data/log/hilog                  // Obtain the stored HiLog logs (including kernel logs).
1150```
1151
1152## FAQs
1153
1154### Failed to Identify the Target Device
1155
1156**Symptom**
1157
1158After the **hdc list targets** command is executed, the command output is **[empty]**.
1159
1160**Possible Causes and Solution**
1161
1162Perform the following operations to locate the fault.
1163
1164- Case 1: Check whether the target device is displayed in **Device Manager**.
1165
1166   Windows:
1167
1168   Check whether **HDC Device** (for a single-port device) or **HDC Interface** (for a composite device) exists under **Universal Serial Bus Controllers** in **Device Manager**.
1169
1170   Linux:
1171
1172   Run the **lsusb** command. Check whether **HDC Device** or **HDC Interface** is displayed in the command output.
1173
1174   macOS:
1175
1176   View USB devices in **System Information** or **System Overview**.
1177
1178   1. Press and hold the **Option** key, and click **Menu**.
1179
1180   2. Choose **System Information** or **System Overview**.
1181
1182   3. Select **USB** on the left.
1183
1184   4. Check whether **HDC Device** or **HDC Interface** exists in the device tree.
1185
1186   **Solution**
1187
1188   If the device is not displayed, it fails to be identified. You can use any of the following methods to resolve the problem:
1189
1190   - Use another physical USB port.
1191   - Replace the USB cable.
1192   - Use another PC for debugging.
1193   - Enable the USB debugging mode.
1194   - Click **OK** to allow USB debugging.
1195   - If a TCP connection can be set up, run the **hdc tmode usb** command to switch to the USB connection.
1196   - Restore the factory settings of the device.
1197
1198- Case 2: A USB device exists, but the driver is damaged. **HDC Device** with a warning icon in yellow is displayed.
1199
1200   This problem usually occurs in Windows. In **Device Manager/Universal Serial Bus Device**, **HDC Device** is displayed with a yellow warning icon, indicating that the device cannot work properly. To resolve the problem, reinstall the driver. If the problem persists, use another USB cable, docking station, or USB port.
1201
1202   **Reinstalling the Driver**
1203
1204   1. Open **Device Manager**, and right-click the **HDC Device** with a warning icon.
1205
1206   2. In the displayed menu, choose **Update driver**.
1207
1208   3. In the first prompt window, select **Browse my computer for drivers**.
1209
1210   4. In the second prompt window, select **Let me pick from a list of available drivers on my computer**.
1211
1212   5. In the third prompt window, deselect **Show compatible hardware**, select **WinUsb Device** for **Manufacture** and **WinUsb Device** for **Model**, and click **Next**.
1213
1214- Case 3: "[Fail]Failed to communicate with daemon" is displayed when the device is connected.
1215
1216   When "[Fail]Failed to communicate with daemon" is displayed after a hdc command is executed.
1217
1218   Possible causes are as follows:
1219
1220   - The hdc or SDK does not match the device. If the device is the latest version, update the hdc or SDK tool to the latest version.
1221   - The port is occupied.
1222
1223   This problem usually occurs when hdc and hdc_std use the same **OHOS_HDC_SERVER_PORT** or the same default port **8710**. Ensure that either hdc or hdc_std is running. This problem also occurs when other software occupies the default hdc port.
1224
1225- Case 4: "Connect server failed" is displayed when the device is connected.
1226
1227   The possible causes are as follows:
1228
1229   - **Port Preemption**
1230
1231      Solution:
1232      1. Check the software processes that come with hdc, including software with built-in hdc, such as DevEco Studio and DevEco Testing.
1233
1234         Stop these software processes and run hdc commands.
1235
1236      2. Check hdc port status.
1237
1238         For example, if **OHOS_HDC_SERVER_PORT** is set to **8710**, run the following command to check the port status.
1239
1240         Unix:
1241
1242         ```shell
1243         netstat -an |grep 8710
1244         ```
1245
1246         Windows:
1247
1248         ```shell
1249         netstat -an |findstr 8710
1250         ```
1251
1252         If the port is used by another software, stop the software process or change the **OHOS_HDC_SERVER_PORT** environment variable to another port number.
1253
1254      3. Check for and stop the hdc server of another version.
1255
1256         Windows:
1257
1258         Choose **Task Manager** > **Details**, right-click the **hdc.exe** process and choose **Open file location**. Check whether the location is the same as that configured in the environment variable. If not, stop the **hdc.exe** process by running the **hdc kill** command or terminating the process in **Task Manager**. Then, run the hdc command again. (The hdc server will be restarted by running the hdc command.)
1259
1260         Unix:
1261
1262         Run the **ps -ef |grep hdc** command to query the hdc server process running in the background and check whether the process startup location is the hdc file location set by the environment variable **Path**. If not, stop the hdc process by running the **hdc kill** or **kill -9 hdc** *PID* command, and run the hdc command again. (The hdc server will be restarted by running the hdc command.)
1263
1264   - **Registry Exception**
1265
1266      Solution: Clear the registry. The procedure is as follows:
1267
1268      1. Press **Win+R** to open the **Run** dialog box, and enter **regedit** to open the registry.
1269      2. Enter the following address in the address bar, and press **Enter** to access the registry of the USB device driver.
1270
1271         ```shell
1272         Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{88bae032-5a81-49f0-bc3d-a4ff138216d6}
1273         ```
1274
1275      3. Right-click **UpperFilters** and choose **Edit**. Back up and clear the value data. The backup data can be used to restore the value data if the problem persists.
1276      4. Refresh the **Device Manager**, remove and reconnect the USB cable to the USB port, or restart the PC.
1277
1278<!--Del-->
1279
1280**The non-root user cannot find the device using hdc in Linux**
1281
1282In Linux, you can enable the USB device operation permission for non-root users as follows:
1283
1284- To temporarily grant the full operation permission on a USB device, run the following command:
1285
1286   ```shell
1287   sudo chmod -R 777 /dev/bus/usb/
1288   ```
1289
1290- To permanently change the operation permission on a USB device, do as follows:
1291
1292   1. Run the **lsusb** command to obtain the **vendorID** and **productID** of the USB device.
1293
1294   2. Create an **udev** rule.
1295
1296      Edit the **udev** loading rule and replace the default **idVendor** and **idProduct** values of the device with the values obtained in the previous step.
1297
1298      **MODE="0666"** indicates the permissions of **GROUP** (the user group) for the USB device. Ensure that the login user is in the user group.
1299
1300         ```shell
1301         sudo vim /etc/udev/rules.d/90-myusb.rules
1302         SUBSYSTEMS=="usb", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", GROUP="users", MODE="0666"
1303         ```
1304
1305   3. Restart the computer or reload the **udev** rule.
1306
1307         ```shell
1308         sudo udevadm control --reload
1309         ```
1310
1311> **NOTE**
1312> A non-root user cannot find the device using hdc in Linux. Granting USB operation permission for non-root users can solve this problem. However, granting the full permission may pose potential security risks. You need to determine whether to grant the permission based on actual requirements.
1313
1314<!--DelEnd-->
1315
1316### Failed to Run hdc
1317
1318**Symptom**
1319
1320The **hdc.exe**/hdc binary file cannot be executed using the CLI.
1321
1322**Possible Causes and Solution**
1323
1324- Incorrect runtime environment.
1325
1326   Linux: Ubuntu 18.04 64-bit or later is recommended. If **libc++.so** reference errors are reported, run the **ldd** or **readelf** command to check library reference.
1327
1328   macOS: macOS 11 or later is recommended.
1329
1330   Windows: Windows 10 or Windows 11 64-bit is recommended. If the WinUSB library or driver is missing in an earlier version, use [Zadig](https://github.com/pbatard/libwdi/releases) to update it. For Windows 10 or Windows 11 64-bit, use [Zadig](https://github.com/pbatard/libwdi/releases) to install the libusb-win32 driver. For details, see [Zadig](https://github.com/pbatard/libwdi/releases).
1331
1332- Improper running mode: Use the correct command to run the hdc tool instead of double-clicking the file.
1333
1334### Common Procedure for Troubleshooting Other Problems
1335
13361. Run the **hdc list targets** command.
13372. Check whether **HDC Device** exists in **Device Manager**.
13383. Run the **hdc kill** command to terminate the server, and then run the **hdc -l5 start** command to collect logs. (The **hdc.log** file is stored in the **TEMP** directory on the execution end. The directory location varies with the OS. For details, see [Server Logs](#server-logs).)
13394. Locate the problem based on the **hdc.log** file.
1340
1341## hdc Error Codes
1342
1343### E003001 The Specified Bundle Name Is Invalid
1344
1345**Error Message**
1346
1347Invalid bundle name: _bundlename_
1348
1349**Symptom**
1350
1351The **_bundlename_** specified in the **hdc shell [-b bundlename] [command]** command is not the bundle name of an installed debug application, or the application directory does not exist.
1352
1353**Possible Causes**
1354
1355* Scenario 1: The specified application is not installed on the device.
1356
1357* Scenario 2: The specified application is not built in debug mode.
1358
1359* Scenario 3: The specified application is not started.
1360
1361**Solution**
1362
1363* Scenario 1: Ensure that the application specified in the command has been installed on the device.
1364
1365   a. Run the **hdc shell "bm dump -a | grep bundlename"** command to check whether the application corresponding to the bundle name has been installed on the device. The expected result is **_bundlename_**.
1366
1367   For example, if the bundle name is **com.example.myapplication**, run the following command:
1368
1369   ```shell
1370   hdc shell "bm dump -a | grep com.example.myapplication"
1371   ```
1372
1373   If the bundle has been installed on the device, the following information is returned:
1374
1375   ```shell
1376   com.example.myapplication
1377   ```
1378
1379   b. If the application is a debug application but is not installed on the device, run the **hdc install [app_path]** command to install it.
1380
1381   c. If the application is not a debug application but a release application, the** _bundlename_** cannot be specified.
1382
1383* Scenario 2: Run the **hdc shell "bm dump -n bundlename | grep debug"** command to check whether the specified application is built in debug mode. The expected result is **"appProvisionType": "debug", "debug": true**.
1384
1385   For example, run the following command to check the bundle name **com.example.myapplication**:
1386
1387   ```shell
1388   hdc shell "bm dump -n com.example.myapplication | grep debug"
1389   ```
1390
1391   If the application corresponding to the bundle name is built in debug mode, the following information is displayed:
1392
1393   ```shell
1394   "appProvisionType": "debug",
1395   "debug": true,
1396   ```
1397
1398   For details about how to build an application in debug mode, see [Building a HAR in Debug Mode](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V5/ide-hvigor-build-har-V5#section197792874110).
1399
1400* Scenario 3: Ensure that the bundle specified by the command has been started.
1401
1402   a. Run the **hdc shell "mount |grep bundlename"** command to check whether the resource directory is mounted after the bundle is started.
1403
1404   For example, to check the bundle name **com.example.myapplication**, run the following command:
1405
1406   ```shell
1407   hdc shell "mount |grep com.example.myapplication"
1408   ```
1409
1410   If the corresponding resource directory has been mounted, mounting information is expected to be returned. (The returned information varies according to the actual mounting status and is not displayed here.)
1411
1412   If the corresponding resource directory is not mounted, no information is returned.
1413
1414   b. If the corresponding resource directory is not mounted, you can click the application or run the **aa** command to start the application.
1415
1416   For example, to start the application whose name is **com.example.myapplication** and module name is **EntryAbility**, run the following command:
1417
1418   ```shell
1419   hdc shell aa start -b com.example.myapplication -a EntryAbility
1420   ```
1421
1422   For details, see [aa Commands](../tools/aa-tool.md).
1423
1424### E003002 The Parameter Specified in the Command Does Not Support the Interactive Option
1425
1426**Error Message**
1427
1428Unsupport interactive shell command option
1429
1430**Symptom**
1431
1432The **hdc shell [-b bundlename] [command]** command does not support the interactive option.
1433
1434**Possible Causes**
1435
1436The **_command_** parameter specified in **hdc shell [-b bundlename] [command]** is empty.
1437
1438**Solution**
1439
1440Ensure that the **_command_** parameter of the command is not empty. For details, see [Running the Interactive Command](#running-the-interactive-command).
1441
1442### E003003 The Command Option Is Not Supported
1443
1444**Error Message**
1445
1446Unsupported shell option: _option_
1447
1448**Symptom**
1449
1450The **hdc shell [-b bundlename] [command]** command contains the unsupported parameter **_option_**.
1451
1452**Possible Causes**
1453
1454The **hdc shell [-b bundlename] [command]** command specifies the unsupported command parameters, such as **-f** and **-B**. The parameters are case sensitive.
1455
1456**Solution**
1457
1458Use the parameter supported by the current version, for example, **-b**.
1459
1460### E003004 The Command Parameter Is Not Supported by the Device
1461
1462**Error Message**
1463
1464Device does not supported this shell command
1465
1466**Symptom**
1467
1468An unsupported parameter is specified in the **hdc shell [-b bundlename] [command]** command.
1469
1470**Possible Causes**
1471
1472The system version of the device is too early to support the new command parameters.
1473
1474**Solution**
1475
1476Upgrade the device system to the latest version.
1477
1478### E003005 The Parameter Is Missing
1479
1480**Error Message**
1481
1482The parameter is missing, correct your input by referring below: _Usage_
1483
1484**Symptom**
1485
1486Mandatory parameters are missing in the **hdc shell [-b bundlename] [command]** command.
1487
1488**Possible Causes**
1489
1490When the **-b** option is specified in the command, the **_bundlename_** and **_command_** parameters are missing. For details about the parameters, see [Running the Interactive Command](#running-the-interactive-command).
1491
1492**Solution**
1493
1494Ensure that the **_bundlename_** and **_command_** parameters of the command are not empty.
1495
1496### E005101 The Specified Bundle Name Is Invalid During File Transfer
1497
1498**Error Message**
1499
1500Invalid bundle name: _bundlename_
1501
1502**Symptom**
1503
1504The specified **_bundlename_** in the **hdc file send/recv [-b bundlename] [localpath] [remotepath]** command is not the bundle name of an installed debug application, or the application directory does not exist.
1505
1506**Possible Causes**
1507
1508Same as [E003001 The Specified Bundle Name Is Invalid](#e003001-the-specified-bundle-name-is-invalid).
1509
1510**Solution**
1511
1512Same as [E003001 The Specified Bundle Name Is Invalid](#e003001-the-specified-bundle-name-is-invalid).
1513
1514### E005102 The Remote Path Is Invalid
1515
1516**Error Message**
1517
1518Remote path: _remotepath_ is invalid, it is out of the application directory.
1519
1520**Symptom**
1521
1522The path specified by **_remotepath_** in the **hdc file send [-b bundlename] [localpath] [remotepath]** command does not exist or exceeds the application data directory.
1523
1524The path specified by **_remotepath_** in the **hdc file recv [-b bundlename] [remotepath] [localpath]** command does not exist or exceeds the application data directory.
1525
1526**Possible Causes**
1527
1528* Scenario 1: The path does not exist.
1529
1530* Scenario 2: The **_remotepath_ parameter** contains the **..** redirection symbol. After the redirection, the directory exceeds the application data root directory.
1531
1532**Solution**
1533
1534Check whether the relative path of the application data directory specified by **_remotepath_** exists.
1535
1536### E005003 The Parameter Is Missing During File Transfer
1537
1538**Error Message**
1539
1540The parameter is missing, correct your input by referring below: _Usage_
1541
1542**Symptom**
1543
1544Mandatory parameters are missing in the **hdc file send [-b bundlename] [localpath] [remotepath]** command.
1545
1546Mandatory parameters are missing in the **hdc file recv [-b bundlename] [remotepath] [localpath]** command.
1547
1548**Possible Causes**
1549
1550When the **-b** option is specified in the command, the **_bundlename_**, **_localpath_** and **_remotepath_** parameters are missing. For details about the parameters, see [Transferring Files](#transferring-files).
1551
1552**Solution**
1553
1554Ensure that the **_bundlename_**, **_localpath_** and **_remotepath_** parameters in the command are not empty.
1555
1556### E005004 The SDK or Device System Version Does Not Support the -b Option
1557
1558**Error Message**
1559
1560SDK/Device ROM doesn't support -b option.
1561
1562**Symptom**
1563
1564The **hdc file send/recv** command contains the **-b** option, but the hdc in SDK or device system version does not support this option.
1565
1566**Possible Causes**
1567
1568* Scenario 1: When the **hdc file send [-b bundlename] [localpath] [remotepath]** command is executed, the device system does not support the **-b** option.
1569
1570* Scenario 2: When the **hdc file recv [-b bundlename] [remotepath] [localpath]** command is executed, the hdc in SDK does not support the **-b** option.
1571
1572**Solution**
1573
1574* Scenario 1: Update the system to the latest version.
1575
1576* Scenario 2: Upgrade the SDK to the latest version.
1577