• 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
464The command format is as follows:
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 commands
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   | No return value | The server is started successfully.|
753
754   **Usage**
755
756   ```shell
757   hdc start
758   hdc start -r // Restart the server.
759   ```
760
761   > **NOTE**
762   >
763   > 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**.
764
7652. Terminate the hdc server.
766
767   ```shell
768   hdc kill [-r]
769   ```
770
771   **Return value**
772   | Return Value| Description|
773   | -------- | -------- |
774   | Kill server finish | The server is terminated successfully.|
775   | [Fail]Error information| Failed to terminate the server.|
776
777   **Usage**
778
779   ```shell
780   hdc kill
781   hdc kill -r // Restart and terminate the server process.
782   ```
783
7843. Execute a client command without querying the server.
785
786   ```shell
787   hdc -p [command]
788   ```
789
790   **Parameters**
791   | Parameter| Description|
792   | -------- | -------- |
793   | command | Command to be executed.|
794
795   **Return value**
796   | Return Value| Description|
797   | -------- | -------- |
798   | Connect server failed | Fails to connect to the server.|
799
800   **Usage**
801
802   ```shell
803   # Start a background server.
804   hdc start
805   # Execute the command directly without querying the server.
806   hdc -p list targets
807   ```
808
809   > **NOTE**
810   >
811   > 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.
812
8134. Start the server process in the foreground.
814
815   ```shell
816   hdc -m
817   ```
818
819   **Return value**
820   | Return Value| Description|
821   | -------- | -------- |
822   | Initial failed | The server process fails to be initialized.|
823   | [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.|
824
825   **Usage**
826
827   ```shell
828   # Start a server process with the IP address and port number specified.
829   hdc -s 127.0.0.1:8710 -m
830   ```
831
832   > **NOTE**
833   >
834   > 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**.
835   > 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.
836   > 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.
837
838## Operating the Device
839
840| Command| Description|
841| -------- | -------- |
842| hilog [-h] | Displays the log information of the device. You can run the **hdc hilog -h** command to obtain the supported parameters. |
843| jpid | Displays the PIDs of all applications that have enabled JDWP on the device.|
844| 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.|
845| 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.|
846| target boot [MODE] | Restart the target device to enter the corresponding mode. **MODE** is an option supported by **reboot** in the **/bin/begetctl** command.|
847| <!--DelRow--> target mount | Mounts the system partition in read/write mode. (This command is supported after the device has required the root permission.)|
848| <!--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.)|
849
8501. Display the log information of the device.
851
852   ```shell
853   hdc hilog [-h]
854   ```
855
856   **Parameters**
857   | Parameter| Description|
858   | -------- | -------- |
859   | [-h] | Parameters supported by HiLog. You can run the **hdc hilog -h** command to obtain the parameter list.|
860
861   **Return value**
862   | Return Value| Description|
863   | -------- | -------- |
864   | Returned information| Log information obtained.|
865
866   **Usage**
867
868   ```shell
869   hdc hilog
870   ```
871
8722. Display the PIDs of all processes that enable JDWP.
873
874   ```shell
875   hdc jpid
876   ```
877
878   **Return value**
879   | Return Value| Description|
880   | -------- | -------- |
881   | PID list| PIDs of the applications that enable JDWP.|
882   | [empty] | No process enables JDWP.|
883
884   **Usage**
885
886   ```shell
887   hdc jpid
888   ```
889
8903. Display the PIDs and application names of the processes that enable JDWP on the device in real time.
891
892   ```shell
893   track-jpid [-a|-p]
894   ```
895
896   **Parameters**
897   | Parameter| Description|
898   | -------- | -------- |
899   | Not specified| Used to display only the PIDs, bundle names, and process names of **debug** applications.|
900   | -a | Used to display the PIDs, bundle names, and process names of the **debug** and **release** applications. |
901   | -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.|
902
903   **Return value**
904   | Return Value| Description|
905   | -------- | -------- |
906   | PIDs and bundle/process name list| - |
907   | [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.|
908
909   **Usage**
910
911   ```shell
912   hdc track-jpid
913   ```
914
9154. Restart the target device.
916
917   ```shell
918   target boot [-bootloader|-recovery]
919   target boot [MODE]
920   ```
921
922   **Parameters**
923   | Name| Description|
924   | -------- | -------- |
925   | Not specified| Used to restart a device.|
926   | -bootloader| Used to restart a device to enter the **fastboot** mode.|
927   | -recovery | Used to restart a device to enter the **recovery** mode.|
928   | 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.|  |
929
930   **Usage**
931
932   ```shell
933   hdc target boot -bootloader // Restart the device to enter the fastboot mode.
934   hdc target boot -recovery // Restart the device to enter the recovery mode.
935   hdc target boot shutdown // Shut down the device.
936   ```
937
938<!--Del-->
9395. Mount the system partition in read/write mode.
940
941   ```shell
942   hdc target mount
943   ```
944
945   **Return value**
946   | Return Value| Description|
947   | -------- | -------- |
948   | Mount finish | Mounting succeeded.|
949   | [Fail]Mount failed | Mounting failed.|
950
951   **Usage**
952
953   ```shell
954   hdc target mount
955   ```
956
957   > **NOTE**
958   >
959   > This command is supported only after the device has required the root permission. Exercise caution when running this command.
960
9616. Grant the **root** permission to the background hdc server running on the device.
962
963   ```shell
964   hdc smode [-r]
965   ```
966
967   **Return value**
968   | Return Value| Description|
969   | -------- | -------- |
970   | No return value| Permission granted.|
971   | [Fail]Error information| Failed to grant the permission.|
972
973   **Usage**
974
975   ```shell
976   hdc smode
977   hdc smode -r  // Revoke the root permission.
978   ```
979
980   > **NOTE**
981   >
982   > This command is supported only after the device has required the **root** permission.
983
984<!--DelEnd-->
985
986## Security Command
987
988| Command| Description|
989| -------- | -------- |
990| 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.|
991
9921. Generate a new key pair.
993
994   ```shell
995   hdc keygen FILE
996   ```
997
998   **Parameters**
999   | Parameter| Description|
1000   | -------- | -------- |
1001   | FILE | Custom file name.|
1002
1003   **Usage**
1004
1005   ```shell
1006   hdc keygen key // Generate the key and key.pub files in the current directory.
1007   ```
1008
1009## Obtaining the Version Number
1010
1011| Command| Description|
1012| -------- | -------- |
1013| -v/version | Displays hdc version information.|
1014| checkserver | Obtains the client and server process versions.|
1015
10161. Display hdc version information.
1017
1018   ```shell
1019   hdc -v/version
1020   ```
1021
1022   **Return value**
1023   | Return Value| Description|
1024   | -------- | -------- |
1025   | Ver: X.X.Xa | hdc (SDK) version information.|
1026
1027   **Usage**
1028
1029   ```shell
1030   hdc -v or hdc version
1031   ```
1032
10332. Obtain the client and server process versions.
1034
1035   ```shell
1036   hdc checkserver
1037   ```
1038
1039   **Return value**
1040   | Return Value| Description|
1041   | -------- | -------- |
1042   | Client version: Ver: X.X.Xa, Server version: Ver: X.X.Xa | The client and server versions.|
1043
1044   **Usage**
1045
1046   ```shell
1047   hdc checkserver
1048   ```
1049
1050## hdc Debugging Logs
1051
1052### Server Logs
1053
1054#### Log level
1055
1056Specify the hdc log level. The default value is **LOG_INFO**.
1057
1058   ```shell
1059   hdc -l [level] [command]
1060   ```
1061
1062   **Parameters**
1063| Parameter| Description|
1064| -------- | -------- |
1065| [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|
1066| command | Command to be executed.|
1067
1068   > **NOTE**
1069   >
1070   > 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.
1071   > 2. You can change only the log levels of the current client and server processes.
1072
1073   **Return value**
1074| Return Value| Description|
1075| -------- | -------- |
1076| Command output| Command execution result, which may vary with the command.|
1077| Log information| Logs of the specified level.|
1078
1079   **Usage**
1080
1081   Run the **shell ls** command with the log level specified to **LOG_DEBUG**.
1082
1083   ```shell
1084   hdc -l 5 shell ls
1085   ```
1086
1087   Run the **-m** command with the log level specify to **LOG_LIBUSB**.
1088
1089   ```shell
1090   hdc kill && hdc -l 6 -m
1091   ```
1092
1093   > **NOTE**
1094   > 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.
1095
1096   Start the server process in the background with the log level set to **LOG_LIBUSB**.
1097
1098   ```shell
1099   hdc kill && hdc -l 6 start
1100   ```
1101
1102   > **NOTE**
1103   > 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**.
1104
1105#### Obtaining Logs
1106
1107Obtain server logs.
1108
1109```shell
1110hdc kill
1111hdc -l5 start
1112```
1113
1114The collected logs are stored in the following path.
1115
1116| OS | Path | Remarks |
1117| -------- | -------- | -------- |
1118| Windows | %temp%\hdc.log | The following are examples. Replace *Username* with the actual one.<br/>C:\Users\Username\AppData\Local\Temp\hdc.log**.|
1119| Linux | /tmp/hdc.log | - |
1120| MacOS | $TMPDIR/hdc.log | - |
1121
1122Log-related environment variables
1123
1124| Environment Variable            | Default Value| Description                            |
1125|--------------------|-----|--------------------------------|
1126| OHOS_HDC_LOG_LEVEL | 5   | The log level of the server process.<br>For details, see [Server Logs](#server-logs). |
1127
1128Configure environment variables as follows:
1129
1130The following shows how to set the **OHOS_HDC_LOG_LEVEL** environment variable to **5**.
1131
1132| OS| Configuration Method|
1133|---|---|
1134| 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. |
1135| 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.|
1136| 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.|
1137
1138### Device Logs
1139
1140Enable HiLog to obtain the corresponding logs.
1141
1142```shell
1143hdc shell hilog -w start                             // Enable the function of storing HiLog logs.
1144hdc shell ls /data/log/hilog                     // View the stored HilLog logs.
1145hdc file recv /data/log/hilog                  // Obtain the stored HilLog logs (including kernel logs).
1146```
1147
1148## FAQs
1149
1150### Failed to Identify the Target Device
1151
1152**Symptom**
1153
1154After the **hdc list targets** command is executed, the command output is **[empty]**.
1155
1156**Possible Causes and Solution**
1157
1158Perform the following operations to locate the fault.
1159
1160- Case 1: Check whether the target device is displayed in **Device Manager**.
1161
1162   Windows:
1163
1164   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**.
1165
1166   Linux:
1167
1168   Run the **lsusb** command. Check whether **HDC Device** or **HDC Interface** is displayed in the command output.
1169
1170   macOS:
1171
1172   View USB devices in **System Information** or **System Overview**.
1173
1174   1. Press and hold the **Option** key, and click **Menu**.
1175
1176   2. Choose **System Information** or **System Overview**.
1177
1178   3. Select **USB** on the left.
1179
1180   4. Check whether **HDC Device** or **HDC Interface** exists in the device tree.
1181
1182   **Solution**
1183
1184   If the device is not displayed, it fails to be identified. You can use any of the following methods to resolve the problem:
1185
1186   - Use another physical USB port.
1187   - Replace the USB cable.
1188   - Use another PC for debugging.
1189   - Enable the USB debugging mode.
1190   - Click **OK** to allow USB debugging.
1191   - If a TCP connection can be set up, run the **hdc tmode usb** command to switch to the USB connection.
1192   - Restore the factory settings of the device.
1193
1194- Case 2: A USB device exists, but the driver is damaged. **HDC Device** with a warning icon in yellow is displayed.
1195
1196   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.
1197
1198   **Reinstalling the Driver**
1199
1200   1. Open **Device Manager**, and right-click the **HDC Device** with a warning icon.
1201
1202   2. In the displayed menu, choose **Update driver**.
1203
1204   3. In the first prompt window, select **Browse my computer for drivers**.
1205
1206   4. In the second prompt window, select **Let me pick from a list of available drivers on my computer**.
1207
1208   5. In the third prompt window, deselect **Show compatible hardware**, select **WinUsb Device** for **Manufacture** and **WinUsb Device** for **Model**, and click **Next**.
1209
1210- Case 3: "[Fail]Failed to communicate with daemon" is displayed when the device is connected.
1211
1212   When "[Fail]Failed to communicate with daemon" is displayed after a hdc command is executed.
1213
1214   Possible causes are as follows:
1215
1216   - 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.
1217   - The port is occupied.
1218
1219   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.
1220
1221- Case 4: "Connect server failed" is displayed when the device is connected.
1222
1223   The possible causes are as follows:
1224
1225   - **Port Preemption**
1226
1227      Solution:
1228      1. Check the software processes that come with hdc, including software with built-in hdc, such as DevEco Studio and DevEco Testing.
1229
1230         Stop these software processes and run hdc commands.
1231
1232      2. Check hdc port status.
1233
1234         For example, if **OHOS_HDC_SERVER_PORT** is set to **8710**, run the following command to check the port status.
1235
1236         Unix:
1237
1238         ```shell
1239         netstat -an |grep 8710
1240         ```
1241
1242         Windows:
1243
1244         ```shell
1245         netstat -an |findstr 8710
1246         ```
1247
1248         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.
1249
1250      3. Check for and stop the hdc server of another version.
1251
1252         Windows:
1253
1254         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.)
1255
1256         Unix:
1257
1258         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.)
1259
1260   - **Registry Exception**
1261
1262      Solution: Clear the registry. The procedure is as follows:
1263
1264      1. Press **Win+R** to open the **Run** dialog box, and enter **regedit** to open the registry.
1265      2. Enter the following address in the address bar, and press **Enter** to access the registry of the USB device driver.
1266
1267         ```shell
1268         Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{88bae032-5a81-49f0-bc3d-a4ff138216d6}
1269         ```
1270
1271      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.
1272      4. Refresh the **Device Manager**, remove and reconnect the USB cable to the USB port, or restart the PC.
1273
1274<!--Del-->
1275
1276**The non-root user cannot find the device using hdc in Linux**
1277
1278In Linux, you can enable the USB device operation permission for non-root users as follows:
1279
1280- To temporarily grant the full operation permission on a USB device, run the following command:
1281
1282   ```shell
1283   sudo chmod -R 777 /dev/bus/usb/
1284   ```
1285
1286- To permanently change the operation permission on a USB device, do as follows:
1287
1288   1. Run the **lsusb** command to obtain the **vendorID** and **productID** of the USB device.
1289
1290   2. Create an **udev** rule.
1291
1292      Edit the **udev** loading rule and replace the default **idVendor** and **idProduct** values of the device with the values obtained in the previous step.
1293
1294      **MODE="0666"** indicates the permissions of **GROUP** (the user group) for the USB device. Ensure that the login user is in the user group.
1295
1296         ```shell
1297         sudo vim /etc/udev/rules.d/90-myusb.rules
1298         SUBSYSTEMS=="usb", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", GROUP="users", MODE="0666"
1299         ```
1300
1301   3. Restart the computer or reload the **udev** rule.
1302
1303         ```shell
1304         sudo udevadm control --reload
1305         ```
1306
1307> **NOTE**
1308> 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.
1309
1310<!--DelEnd-->
1311
1312### Failed to Run hdc
1313
1314**Symptom**
1315
1316The **hdc.exe**/hdc binary file cannot be executed using the CLI.
1317
1318**Possible Causes and Solution**
1319
1320- Incorrect runtime environment.
1321
1322   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.
1323
1324   macOS: macOS 11 or later is recommended.
1325
1326   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).
1327
1328- Improper running mode: Use the correct command to run the hdc tool instead of double-clicking the file.
1329
1330### Common Procedure for Troubleshooting Other Problems
1331
13321. Run the **hdc list targets** command.
13332. Check whether **HDC Device** exists in **Device Manager**.
13343. 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).)
13354. Locate the problem based on the **hdc.log** file.
1336
1337## hdc Error Codes
1338
1339### E003001 The Specified Bundle Name Is Invalid
1340
1341**Error Message**
1342
1343Invalid bundle name: _bundlename_
1344
1345**Symptom**
1346
1347The **_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.
1348
1349**Possible Causes**
1350
1351* Scenario 1: The specified application is not installed on the device.
1352
1353* Scenario 2: The specified application is not built in debug mode.
1354
1355* Scenario 3: The specified application is not started.
1356
1357**Solution**
1358
1359* Scenario 1: Ensure that the application specified in the command has been installed on the device.
1360
1361   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_**.
1362
1363   For example, if the bundle name is **com.example.myapplication**, run the following command:
1364
1365   ```shell
1366   hdc shell "bm dump -a | grep com.example.myapplication"
1367   ```
1368
1369   If the bundle has been installed on the device, the following information is returned:
1370
1371   ```shell
1372   com.example.myapplication
1373   ```
1374
1375   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.
1376
1377   c. If the application is not a debug application but a release application, the** _bundlename_** cannot be specified.
1378
1379* 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**.
1380
1381   For example, run the following command to check the bundle name **com.example.myapplication**:
1382
1383   ```shell
1384   hdc shell "bm dump -n com.example.myapplication | grep debug"
1385   ```
1386
1387   If the application corresponding to the bundle name is built in debug mode, the following information is displayed:
1388
1389   ```shell
1390   "appProvisionType": "debug",
1391   "debug": true,
1392   ```
1393
1394   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).
1395
1396* Scenario 3: Ensure that the bundle specified by the command has been started.
1397
1398   a. Run the **hdc shell "mount |grep bundlename"** command to check whether the resource directory is mounted after the bundle is started.
1399
1400   For example, to check the bundle name **com.example.myapplication**, run the following command:
1401
1402   ```shell
1403   hdc shell "mount |grep com.example.myapplication"
1404   ```
1405
1406   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.)
1407
1408   If the corresponding resource directory is not mounted, no information is returned.
1409
1410   b. If the corresponding resource directory is not mounted, you can click the application or run the **aa** command to start the application.
1411
1412   For example, to start the application whose name is **com.example.myapplication** and module name is **EntryAbility**, run the following command:
1413
1414   ```shell
1415   hdc shell aa start -b com.example.myapplication -a EntryAbility
1416   ```
1417
1418   For details, see [aa Commands](../tools/aa-tool.md).
1419
1420### E003002 The Parameter Specified in the Command Does Not Support the Interactive Option
1421
1422**Error Message**
1423
1424Unsupport interactive shell command option
1425
1426**Symptom**
1427
1428The **hdc shell [-b bundlename] [command]** command does not support the interactive option.
1429
1430**Possible Causes**
1431
1432The **_command_** parameter specified in **hdc shell [-b bundlename] [command]** is empty.
1433
1434**Solution**
1435
1436Ensure that the **_command_** parameter of the command is not empty. For details, see [Running the Interactive Command](#running-the-interactive-command).
1437
1438### E003003 The Command Option Is Not Supported
1439
1440**Error Message**
1441
1442Unsupported shell option: _option_
1443
1444**Symptom**
1445
1446The **hdc shell [-b bundlename] [command]** command contains the unsupported parameter **_option_**.
1447
1448**Possible Causes**
1449
1450The **hdc shell [-b bundlename] [command]** command specifies the unsupported command parameters, such as **-f** and **-B**. The parameters are case sensitive.
1451
1452**Solution**
1453
1454Use the parameter supported by the current version, for example, **-b**.
1455
1456### E003004 The Command Parameter Is Not Supported by the Device
1457
1458**Error Message**
1459
1460Device does not supported this shell command
1461
1462**Symptom**
1463
1464An unsupported parameter is specified in the **hdc shell [-b bundlename] [command]** command.
1465
1466**Possible Causes**
1467
1468The system version of the device is too early to support the new command parameters.
1469
1470**Solution**
1471
1472Upgrade the device system to the latest version.
1473
1474### E003005 The Parameter Is Missing
1475
1476**Error Message**
1477
1478The parameter is missing, correct your input by referring below: _Usage_
1479
1480**Symptom**
1481
1482Mandatory parameters are missing in the **hdc shell [-b bundlename] [command]** command.
1483
1484**Possible Causes**
1485
1486When 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).
1487
1488**Solution**
1489
1490Ensure that the **_bundlename_** and **_command_** parameters of the command are not empty.
1491
1492### E005101 The Specified Bundle Name Is Invalid During File Transfer
1493
1494**Error Message**
1495
1496Invalid bundle name: _bundlename_
1497
1498**Symptom**
1499
1500The 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.
1501
1502**Possible Causes**
1503
1504Same as [E003001 The Specified Bundle Name Is Invalid](#e003001-the-specified-bundle-name-is-invalid).
1505
1506**Solution**
1507
1508Same as [E003001 The Specified Bundle Name Is Invalid](#e003001-the-specified-bundle-name-is-invalid).
1509
1510### E005102 The Remote Path Is Invalid
1511
1512**Error Message**
1513
1514Remote path: _remotepath_ is invalid, it is out of the application directory.
1515
1516**Symptom**
1517
1518The path specified by **_remotepath_** in the **hdc file send [-b bundlename] [localpath] [remotepath]** command does not exist or exceeds the application data directory.
1519
1520The path specified by **_remotepath_** in the **hdc file recv [-b bundlename] [remotepath] [localpath]** command does not exist or exceeds the application data directory.
1521
1522**Possible Causes**
1523
1524* Scenario 1: The path does not exist.
1525
1526* Scenario 2: The **_remotepath_ parameter** contains the **..** redirection symbol. After the redirection, the directory exceeds the application data root directory.
1527
1528**Solution**
1529
1530Check whether the relative path of the application data directory specified by **_remotepath_** exists.
1531
1532### E005003 The Parameter Is Missing During File Transfer
1533
1534**Error Message**
1535
1536The parameter is missing, correct your input by referring below: _Usage_
1537
1538**Symptom**
1539
1540Mandatory parameters are missing in the **hdc file send [-b bundlename] [localpath] [remotepath]** command.
1541
1542Mandatory parameters are missing in the **hdc file recv [-b bundlename] [remotepath] [localpath]** command.
1543
1544**Possible Causes**
1545
1546When 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).
1547
1548**Solution**
1549
1550Ensure that the **_bundlename_**, **_localpath_** and **_remotepath_** parameters in the command are not empty.
1551
1552### E005004 The SDK or Device System Version Does Not Support the -b Option
1553
1554**Error Message**
1555
1556SDK/Device ROM doesn't support -b option.
1557
1558**Symptom**
1559
1560The **hdc file send/recv** command contains the **-b** option, but the hdc in SDK or device system version does not support this option.
1561
1562**Possible Causes**
1563
1564* Scenario 1: When the **hdc file send [-b bundlename] [localpath] [remotepath]** command is executed, the device system does not support the **-b** option.
1565
1566* Scenario 2: When the **hdc file recv [-b bundlename] [remotepath] [localpath]** command is executed, the hdc in SDK does not support the **-b** option.
1567
1568**Solution**
1569
1570* Scenario 1: Update the system to the latest version.
1571
1572* Scenario 2: Upgrade the SDK to the latest version.
1573