鸿蒙模拟器网络代理及HDC安装

问题现象:

模拟器设置网络代理后,代码报错

{"error":{"code":1007900060,"message":"SSL peer certificate or SSH remote key was not OK"}}

charles报错

SSL handshake with client failed: CA certificate could not be matched with a known, trusted CA (unknown_ca
You may need to configure your browser or application to trust the Charles Root Certificate. See SSL Proxying in the Help menu.

网络请求不通,需要给模拟器安装SSL证书

处理步骤

  1. 将charlse证书下载到本地 Help->SSL Proxying -> Save Root cer
    拖到模拟器内,会自动下载到我的手机->下载
  2. 需要安装调试工具hdc,hdc的路径跟教程里不同,在/Applications/DevEco-Studio.app/Contents/sdk/HarmonyOS-NEXT-DB2/openharmony/toolchains/hdc
  3. vi ~/.zshrc
##配置hdc 端口
HDC_SERVER_PORT=7035
launchctl setenv HDC_SERVER_PORT $HDC_SERVER_PORT
export HDC_SERVER_PORT
##配置全局变量,注意hdc的位置,跟教程不同
HDC_SDK_PATH=/Applications/DevEco-Studio.app/Contents/sdk/HarmonyOS-NEXT-DB2/openharmony/toolchains
launchctl setenv HDC_SDK_PATH $HDC_SDK_PATH # 仅MacOS需要在此执行,Linux无须执行
export PATH=$PATH:$HDC_SDK_PATH
  1. source ~/.zshrc
  2. 此时调用hdc,会展示
Unknown operation command...

                         OpenHarmony device connector(HDC) ...

---------------------------------global commands:----------------------------------
 -h/help [verbose]                     - Print hdc help, 'verbose' for more other cmds
 -v/version                            - Print hdc version
 -t connectkey                         - Use device with given connect key

---------------------------------component commands:-------------------------------
session commands(on server):
 list targets [-v]                     - List all devices status, -v for detail
 start [-r]                            - Start server. If with '-r', will be restart server
 kill [-r]                             - Kill server. If with '-r', will be restart server

service commands(on daemon):
 target mount                          - Set /system /vendor partition read-write
 target boot [-bootloader|-recovery]   - Reboot the device or boot into bootloader\recovery.
 target boot [MODE]                    - Reboot the into MODE.
 smode [-r]                            - Restart daemon with root permissions, '-r' to cancel root
                                         permissions
 tmode usb                             - Reboot the device, listening on USB
 tmode port [port]                     - Reboot the device, listening on TCP port

---------------------------------task commands:-------------------------------------
file commands:
 file send [option] local remote       - Send file to device
 file recv [option] remote local       - Recv file from device
                                         option is -a|-s|-z
                                         -a: hold target file timestamp
                                         -sync: just update newer file
                                         -z: compress transfer
                                         -m: mode sync

forward commands:
 fport localnode remotenode            - Forward local traffic to remote device
 rport remotenode localnode            - Reserve remote traffic to local host
                                         node config name format 'schema:content'
                                         examples are below:
                                         tcp:<port>
                                         localfilesystem:<unix domain socket name>
                                         localreserved:<unix domain socket name>
                                         localabstract:<unix domain socket name>
                                         dev:<device name>
                                         jdwp:<pid> (remote only)
 fport ls                              - Display forward/reverse tasks
 fport rm taskstr                      - Remove forward/reverse task by taskstring

app commands:
 install [-r|-s] src                   - Send package(s) to device and install them
                                         src examples: single or multiple packages and directories
                                         (.hap .hsp)
                                         -r: replace existing application
                                         -s: install shared bundle for multi-apps
 uninstall [-k] [-s] package           - Remove application package from device
                                         -k: keep the data and cache directories
                                         -s: remove shared bundle

debug commands:
 hilog [-h]                            - Show device log, -h for detail
 shell [COMMAND...]                    - Run shell command (interactive shell if no command given)
 bugreport [FILE]                      - Return all information from the device, stored in file if FILE is specified
 jpid                                  - List pids of processes hosting a JDWP transport

security commands:
 keygen FILE                           - Generate public/private key; key stored in FILE and FILE.pub
  1. 启动模拟器,本地命令行调用hdc shell aa start -a MainAbility -b com.ohos.certmanager 唤出证书管理 从储存设备中安装->CA证书->继续->我的手机->下载
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容