Symptom
When the HAP is running in the device, the error message "Hdc server port XXXX has been used. Configure environment variable 'OHOS_HDC_SERVER_PORT' and restart DevEco Studio." is displayed.
Solution
This issue occurs because the default HDC port (8710) is being used by another process, preventing the service from starting. To resolve this issue:
Method 1: Stop the application that occupies the port.


Method 2: Set other environment variables for the hdc port number.
Choose This PC > Properties > Advanced system settings > Advances > Environment Variables, add the variable OHOS_HDC_SERVER_PORT, and set its value to any port number not in use, such as 7035.

Then restart DevEco Studio.
Start the terminal and run the following command:
echo $SHELL
vi ~/.bash_profile
vi ~/.zshrc
OHOS_HDC_SERVER_PORT=7035 launchctl setenv OHOS_HDC_SERVER_PORT $OHOS_HDC_SERVER_PORT export OHOS_HDC_SERVER_PORT
Method 3: If the port is not occupied, check whether the port is blocked by the firewall. If it is, unblock the port and then restart DevEco Studio to try again.