# vendor_oobemulator **Repository Path**: ohos-doc/vendor_oobemulator ## Basic Information - **Project Name**: vendor_oobemulator - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: OpenHarmony-5.0.2-Release - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-02-01 - **Last Updated**: 2025-02-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # OpenHarmony 模拟器使用说明 ## 1.标准系统 ### 1.0 编译镜像下载 链接: https://pan.baidu.com/s/1XRko2YkKj_OKlZcJ8XxaKw?pwd=h2xz 提取码: h2xz ### 1.1 OpenHarmony源码下载 ``` repo init -u https://gitee.com/openharmony/manifest -b OpenHarmony-5.0.2-Release --no-repo-verify repo sync -c -j128 repo forall -c 'git lfs pull' ``` ### 1.2 更改内核版本 ``` rm -rf kernel/linux/linux-6.6 git clone -b weekly_20241216 https://gitee.com/openharmony/kernel_linux_6.6.git kernel/linux/linux-6.6 --depth=1 ``` ### 1.3 修改编译脚本 ```//build.sh```(*建议步骤*) 将源码根目录下的./build.sh替换为下列内容,主要修改为添加编译钩子,用于处理patch补丁,即产品编译前添加patch,编译完成后回退patch,不污染OH工程。 ``` #!/bin/bash # Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. set -e set +e echo -e "\n\033[32m\t*********Welcome to OpenHarmony!*********\033[0m\n" echo -e "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" function check_shell_environment() { case $(uname -s) in Linux) shell_result=$(/bin/sh -c 'echo ${BASH_VERSION}') if [ -n "${shell_result}" ]; then echo -e "\033[32mSystem shell: bash ${shell_result}\033[0m" else echo -e "\033[33m Your system shell isn't bash, we recommend you to use bash, because some commands may not be supported in other shells, such as pushd and shopt are not supported in dash. \n You can follow these tips to modify the system shell to bash on Ubuntu: \033[0m" echo -e "\033[33m [1]:Open the Terminal tool and execute the following command: sudo dpkg-reconfigure dash \n [2]:Enter the password and select \033[0m" fi ;; Darwin) echo -e "\033[31m[OHOS ERROR] Darwin system is not supported yet\033[0m" ;; *) echo -e "\033[31m[OHOS ERROR] Unsupported this system: $(uname -s)\033[0m" exit 1 esac } check_shell_environment echo -e "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" echo -e "\033[32mCurrent time: $(date +%F' '%H:%M:%S)\033[0m" echo -e "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" echo -e "\033[32mBuild args: $@\033[0m" echo -e "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++" export SOURCE_ROOT_DIR=$(cd $(dirname $0);pwd) while [[ ! -f "${SOURCE_ROOT_DIR}/.gn" ]]; do SOURCE_ROOT_DIR="$(dirname "${SOURCE_ROOT_DIR}")" if [[ "${SOURCE_ROOT_DIR}" == "/" ]]; then echo -e "\033[31m[OHOS ERROR] Cannot find source tree containing $(pwd)\033[0m" exit 1 fi done if [[ "${SOURCE_ROOT_DIR}x" == "x" ]]; then echo -e "\033[31m[OHOS ERROR] SOURCE_ROOT_DIR cannot be empty.\033[0m" exit 1 fi host_cpu_prefix="" case $(uname -m) in *x86_64) host_cpu_prefix="x86" ;; *arm*) host_cpu_prefix="arm64" ;; *) echo "\033[31m[OHOS ERROR] Unsupported host arch: $(uname -m)\033[0m" RET=1 exit $RET esac case $(uname -s) in Darwin) HOST_DIR="darwin-x86" PYTHON_DIR="darwin-$host_cpu_prefix" HOST_OS="mac" NODE_PLATFORM="darwin-x64" ;; Linux) HOST_DIR="linux-x86" PYTHON_DIR="linux-$host_cpu_prefix" HOST_OS="linux" NODE_PLATFORM="linux-x64" ;; *) echo "\033[31m[OHOS ERROR] Unsupported host platform: $(uname -s)\033[0m" RET=1 exit $RET esac # set python3 PYTHON3_DIR=${SOURCE_ROOT_DIR}/prebuilts/python/${PYTHON_DIR}/current/ PYTHON3=${PYTHON3_DIR}/bin/python3 PYTHON=${PYTHON3_DIR}/bin/python if [[ ! -f "${PYTHON3}" ]]; then echo -e "\033[31m[OHOS ERROR] Please execute the build/prebuilts_download.sh \033[0m" exit 1 else if [[ ! -f "${PYTHON}" ]]; then ln -sf "${PYTHON3}" "${PYTHON}" fi fi export PATH=${SOURCE_ROOT_DIR}/prebuilts/build-tools/${HOST_DIR}/bin:${PYTHON3_DIR}/bin:$PATH # set nodejs and ohpm EXPECTED_NODE_VERSION="14.21.1" export PATH=${SOURCE_ROOT_DIR}/prebuilts/build-tools/common/nodejs/node-v${EXPECTED_NODE_VERSION}-${NODE_PLATFORM}/bin:$PATH export NODE_HOME=${SOURCE_ROOT_DIR}/prebuilts/build-tools/common/nodejs/node-v${EXPECTED_NODE_VERSION}-${NODE_PLATFORM} export PATH=${SOURCE_ROOT_DIR}/prebuilts/build-tools/common/oh-command-line-tools/ohpm/bin:$PATH echo "[OHOS INFO] Current Node.js version is $(node -v)" NODE_VERSION=$(node -v) if [ "$NODE_VERSION" != "v$EXPECTED_NODE_VERSION" ]; then echo -e "\033[31m[OHOS ERROR] Node.js version mismatch. Expected $EXPECTED_NODE_VERSION but found $NODE_VERSION\033[0m" >&2 exit 1 fi echo -e "\033[32m[OHOS INFO] Node.js version check passed!\033[0m" npm config set registry https://repo.huaweicloud.com/repository/npm/ npm config set @ohos:registry https://repo.harmonyos.com/npm/ npm config set strict-ssl false npm config set lockfile false cat $HOME/.npmrc | grep 'lockfile=false' > /dev/null || echo 'lockfile=false' >> $HOME/.npmrc > /dev/null function init_ohpm() { TOOLS_INSTALL_DIR="${SOURCE_ROOT_DIR}/prebuilts/build-tools/common" pushd ${TOOLS_INSTALL_DIR} > /dev/null if [[ ! -f "${TOOLS_INSTALL_DIR}/oh-command-line-tools/ohpm/bin/ohpm" ]]; then echo "[OHOS INFO] download oh-command-line-tools" wget https://repo.huaweicloud.com/harmonyos/ohpm/5.0.2/oh-command-line-tools-20240715.zip -O ohcommandline-tools-linux.zip unzip ohcommandline-tools-linux.zip fi OHPM_HOME=${TOOLS_INSTALL_DIR}/oh-command-line-tools/ohpm/bin chmod +x ${OHPM_HOME}/ohpm export PATH=${OHPM_HOME}:$PATH chmod +x ${OHPM_HOME}/init ${OHPM_HOME}/init > /dev/null echo "[OHOS INFO] Current ohpm version is $(ohpm -v)" ohpm config set registry https://repo.harmonyos.com/ohpm/ ohpm config set strict_ssl false ohpm config set log_level debug popd > /dev/null if [[ -d "$HOME/.hvigor" ]]; then rm -rf $HOME/.hvigor/daemon $HOME/.hvigor/wrapper fi mkdir -p $HOME/.hvigor/wrapper/tools echo '{"dependencies": {"pnpm": "7.30.0"}}' > $HOME/.hvigor/wrapper/tools/package.json pushd $HOME/.hvigor/wrapper/tools > /dev/null echo "[OHOS INFO] installing pnpm..." npm install --silent > /dev/null popd > /dev/null mkdir -p $HOME/.ohpm echo '{"devDependencies":{"@ohos/hypium":"1.0.6"}}' > $HOME/.ohpm/oh-package.json5 pushd $HOME/.ohpm > /dev/null echo "[OHOS INFO] installing hypium..." ohpm install > /dev/null popd > /dev/null } if [[ "$*" != *ohos-sdk* ]]; then echo "[OHOS INFO] Ohpm initialization started..." init_ohpm if [[ "$?" -ne 0 ]]; then echo -e "\033[31m[OHOS ERROR] ohpm initialization failed!\033[0m" exit 1 fi echo -e "\033[32m[OHOS INFO] ohpm initialization successful!\033[0m" fi echo -e "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" hook_path="" params=("$@") param_count=${#params[@]} for ((i=1; i<=param_count; i++)); do param="${params[i]}" case "$param" in --hook) if (( i+1 <= param_count )); then hook_path="${params[i+1]}" i=$((i + 1)) else echo "Error: --hook option requires a path argument, but no more arguments are present." >&2 exit 1 fi ;; esac done if [ -n "$hook_path" ]; then echo -e "\033[32m[OHOS INFO] Start hook_start ...\033[0m" bash $hook_path/hook_start.sh echo -e "\033[32m[OHOS INFO] End hook_start ...\033[0m" fi echo -e "\033[32m[OHOS INFO] Start building...\033[0m\n" function build_sdk() { ROOT_PATH=${SOURCE_ROOT_DIR} SDK_PREBUILTS_PATH=${ROOT_PATH}/prebuilts/ohos-sdk pushd ${ROOT_PATH} > /dev/null echo -e "[OHOS INFO] building the latest ohos-sdk..." ./build.py --product-name ohos-sdk $ccache_args $xcache_args --load-test-config=false --get-warning-list=false --stat-ccache=false --compute-overlap-rate=false --deps-guard=false --generate-ninja-trace=false --gn-args skip_generate_module_list_file=true sdk_platform=linux ndk_platform=linux use_cfi=false use_thin_lto=false enable_lto_O0=true sdk_check_flag=false enable_ndk_doxygen=false archive_ndk=false sdk_for_hap_build=true enable_archive_sdk=false enable_notice_collection=false enable_process_notice=false if [[ "$?" -ne 0 ]]; then echo -e "\033[31m[OHOS ERROR] ohos-sdk build failed! You can try to use '--no-prebuilt-sdk' to skip the build of ohos-sdk.\033[0m" exit 1 fi if [ -d "${ROOT_PATH}/prebuilts/ohos-sdk/linux" ]; then rm -rf ${ROOT_PATH}/prebuilts/ohos-sdk/linux fi mkdir -p ${SDK_PREBUILTS_PATH} mv ${ROOT_PATH}/out/sdk/ohos-sdk/linux ${SDK_PREBUILTS_PATH}/ mkdir -p ${SDK_PREBUILTS_PATH}/linux/native mv ${ROOT_PATH}/out/sdk/sdk-native/os-irrelevant/* ${SDK_PREBUILTS_PATH}/linux/native/ mv ${ROOT_PATH}/out/sdk/sdk-native/os-specific/linux/* ${SDK_PREBUILTS_PATH}/linux/native/ pushd ${SDK_PREBUILTS_PATH}/linux > /dev/null api_version=$(grep apiVersion toolchains/oh-uni-package.json | awk '{print $2}' | sed -r 's/\",?//g') || api_version="11" mkdir -p $api_version for i in */; do if [ -d "$i" ] && [ "$i" != "$api_version/" ]; then mv $i $api_version fi done popd > /dev/null popd > /dev/null } if [[ ! -d "${SOURCE_ROOT_DIR}/prebuilts/ohos-sdk/linux" && "$*" != *ohos-sdk* && "$*" != *"--no-prebuilt-sdk"* || "${@}" =~ "--prebuilt-sdk" ]]; then echo -e "\033[33m[OHOS INFO] The OHOS-SDK was not detected, so the SDK compilation will be prioritized automatically. You can also control whether to execute this process by using '--no-prebuilt-sdk' and '--prebuilt-sdk'.\033[0m" if [[ "${@}" =~ "--ccache=false" || "${@}" =~ "--ccache false" ]]; then ccache_args="--ccache=false" else ccache_args="--ccache=true" fi if [[ "${@}" =~ "--xcache=true" || "${@}" =~ "--xcache true" || "${@}" =~ "--xcache" ]]; then xcache_args="--xcache=true" else xcache_args="--xcache=false" fi build_sdk if [[ "$?" -ne 0 ]]; then echo -e "\033[31m[OHOS ERROR] ohos-sdk build failed, please remove the out/sdk directory and try again!\033[0m" exit 1 fi fi ${PYTHON3} ${SOURCE_ROOT_DIR}/build/scripts/tools_checker.py flag=true args_list=$@ for var in $@ do OPTIONS=${var%%=*} PARAM=${var#*=} if [[ "$OPTIONS" == "using_hb_new" && "$PARAM" == "false" ]]; then flag=false ${PYTHON3} ${SOURCE_ROOT_DIR}/build/scripts/entry.py --source-root-dir ${SOURCE_ROOT_DIR} $args_list break fi done if [[ ${flag} == "true" ]]; then ${PYTHON3} ${SOURCE_ROOT_DIR}/build/hb/main.py build $args_list fi if [[ "$?" -ne 0 ]]; then if [ -n "$hook_path" ]; then echo -e "\033[32m[OHOS INFO] Start hook_ending...\033[0m" bash $hook_path/hook_end.sh echo -e "\033[32m[OHOS INFO] End hook_ending...\033[0m" fi echo -e "\033[31m=====build ${product_name} error=====\033[0m" exit 1 fi if [ -n "$hook_path" ]; then echo -e "\033[32m[OHOS INFO] Start hook_ending...\033[0m" bash $hook_path/hook_end.sh echo -e "\033[32m[OHOS INFO] End hook_ending...\033[0m" fi echo -e "\033[32m=====build ${product_name} successful=====\033[0m" date +%F' '%H:%M:%S echo "++++++++++++++++++++++++++++++++++++++++" ``` #### 使用说明 添加上述代码后,在编译指令后面加上 ```--hook ${hook_patch}``` 目录结构参考 * hook_patch : ```vendor/oobemulator/std_emulator/hook``` ### 1.4 拉取模拟器源码 ``` git clone https://gitee.com/ohos-doc/vendor_oobemulator.git -b OpenHarmony-5.0.2-Release vendor/oobemulator git clone https://gitee.com/ohos-doc/device_board_oobemulator.git -b OpenHarmony-5.0.2-Release device/board/oobemulator git clone https://gitee.com/ohos-doc/device_soc_oobvsoc.git -b OpenHarmony-5.0.2-Release device/soc/oobvsoc ``` ### 1.5 编译 #### 1.5.1 按1.3节修改了```//build.sh```脚本 * 执行 ```./build.sh --product-name std_emulator --hook vendor/oobemulator/std_emulator/hook --ccache``` #### 1.5.2 未修改```//build.sh```脚本 * 1. 注入补丁 ```bash vendor/oobemulator/std_emulator/hook/hook_start.sh``` * 2. 执行 ```./build.sh --product-name std_emulator --ccache``` * 3. 撤销补丁(可选) ```bash vendor/oobemulator/std_emulator/hook/hook_end.sh``` ### 1.6 安装QEMU(Windows) * 1.QEMU下载地址: https://qemu.eu/w64/2024/qemu-w64-setup-20241220.exe * 2.根据指引安装,特别注意的是安装路径默认为: ``` C:\Program Files\qemu ### 请根据需要修改该路径 ``` * 3.将上述路径加入系统```Path```环境变量中。 ### 1.7 启动模拟器 * 1.将编译完成的```images```文件夹复制到windows中,路径如下 ``` out/std_emulator/packages/phone/images ``` * 2.打开命令行终端,切换到images路径,执行: ``` .\run.bat ```