目录

Setting Up the Proxy

The DevEco Studio development environment relies on an Internet connection to ensure the tools function properly.

Generally, if you are using a personal or home network, you do not need to configure proxy information. Proxy configuration is only necessary when you are on an enterprise network that has specific restrictions.

Diagnosing the Development Environment

To get the most out of DevEco Studio, run a diagnostic test on your development environment and fix the failed items based on the provided suggestions. To start a diagnostic test, click Diagnose on the welcome page or choose Help > Diagnostic Tools > Diagnose Development Environment from the menu bar on the project page.

The diagnosis items include the computer configuration and network connectivity. Fix the failed items, if any, based on the provided suggestions.

Configuring the HTTP Proxy

  1. On the welcome page, choose Customize > All settings... > Appearance & Behavior > System Settings > HTTP Proxy. If a project has been opened, choose File > Settings (DevEco Studio > Preferences/Settings on macOS) > Appearance & Behavior > System Settings > HTTP Proxy to access the HTTP Proxy settings page.

    • HTTP parameters: If you are not sure about the information, contact your network administrator.
      • Host name: Enter the host name or IP address of the proxy server.
      • Port number: Enter the port number of the proxy server.
      • No proxy for: Enter the URLs or IP addresses to which your computer can directly connect without a proxy server. Use commas (,) to separate URLs and IP addresses.
    • Proxy authentication parameters: Set the parameters only when the proxy server requires authentication.
      • Login: Enter the username used to access the proxy server.
      • Password: Enter the password used to access the proxy server.
      • Remember: Select this option to remember the password.

  2. When you have finished, click Check connection and enter a URL (for example, https://developer.huawei.com) to check the network connectivity. If the message "Connection successful" is displayed, it indicates that the proxy has been set up successfully.

Setting Up the npm Proxy

During initialization, hvigor and ohpm need to download dependencies from the npm repository. If a proxy is required to access the network, configure the npm proxy as follows.

  1. Go to the C:\Users\username directory and open the .npmrc file. If no .npmrc file is in the directory, create one.

  2. Modify the npm repository information. The following is an example:

    registry=https://repo.huaweicloud.com/repository/npm/
    @ohos:registry=https://repo.harmonyos.com/npm/

  3. Modify the proxy information. In proxy and https-proxy, change the values of user, password, proxyserver, and port based on the actual proxy server. If you are not sure about the information, contact your network administrator. The following is an example:

    proxy=http://user:password@proxy.proxyserver.com:port
    https-proxy=http://user:password@proxy.proxyserver.com:port

    If the password contains special characters, such as @, #, and *, the configuration may not take effect. As such, you are advised to replace the special characters with ASCII codes and add a percent sign (%) before the ASCII codes. Refer to the following for the mapping between common symbols and ASCII codes:

    • !: %21
    • @: %40
    • #: %23
    • $: %24
    • &: %26
    • *: %2A

  4. Add Node.js to environment variables.

    • On Windows:

      Add the Node.js installation path, which is $DevEco Studio installation directory\tools\node by default, to Path under system or user variables.

    • On macOS:
      Start the terminal tool and run the following command:
      export NODE_HOME=/home/xx/Downloads/node-vxx.xx.x-linux-x64  # Replace the path here with the Node.js installation path, which is $DevEco Studio installation directory\tools\node by default.
      export PATH=$NODE_HOME/bin:$PATH

  5. After the proxy is configured, open the CLI and run the following command to check whether the network is normal.

    npm info express

    If the following information is displayed after running the command, it indicates that the proxy has been set up successfully.

Setting Up the ohpm Proxy

To access the ohpm proxy configuration:
  • On the welcome page, choose Customize > All settings... > Build, Execution, Deployment > Ohpm > Optimize config.
  • If a project has been opened, choose File > Settings (DevEco Studio > Preferences/Settings on macOS) > Build, Execution, Deployment > Ohpm > Optimize config to access the ohpm proxy configuration page.

Set the following fields:

After you select and set the preceding fields, click OK.

Note: By default, ohpm verifies the registry address certificate. If a certificate verification error such as "SELF_SIGNED_CERT_IN_CHAIN" or "UNABLE_TO_VERIFY_LEAF_SIGNATURE" is displayed for ohpm registry access during environment diagnosis, see FAQ – Symptom 2 for troubleshooting.

The settings configured on this page are written into the .ohpmrc file in the users/username/.ohpmrc directory. This means that you can also configure the ohpm settings from this file. To do so:

  1. Go to the C:/Users/username/.ohpmrc directory and open the .ohpmrc file. If no .ohpmrc file is in the directory, create one.
  2. Modify the ohpmrc repository information. The following is an example:

    registry=https://ohpm.openharmony.cn/ohpm/

  3. Modify the proxy information. In http_proxy and https_proxy, change the values of user, password, proxyserver, and port based on the actual proxy server. The following is an example:

    http_proxy=http://user:password@proxy.proxyserver.com:port
    https_proxy=http://user:password@proxy.proxyserver.com:port

    If the password contains special characters, such as @, #, and *, the configuration may not take effect. As such, you are advised to replace the special characters with ASCII codes and add "%" before the ASCII codes. Refer to the following for the mapping between common symbols and ASCII codes:

    • !: %21
    • @: %40
    • #: %23
    • $: %24
    • &: %26
    • *: %2A

  4. Add ohpm to environment variables.

    • For Windows:

      Choose This PC > Properties > Advanced System Settings > Advanced > Environment Variables, and add the bin folder path in the ohpm installation path to the Path environment variable under system or user variables. The default path is DevEco Studio installation directory\tools\ohpm.

    • For macOS:
      Start the terminal tool and run the following command:
      export OHPM_HOME=/home/xx/Downloads/ohpm  # Replace the path here with the ohpm installation path, which is /home/xx/Downloads/DevEco Studio installation directory\tools\ohpm by default.
      export PATH=$OHPM_HOME/bin:$PATH

  5. After the proxy is configured, run the following command to check whether the network connectivity is normal.

    ohpm info @ohos/lottie

    If the following information is displayed after running the command, it indicates that the proxy has been set up successfully.