环境准备
系统必须为Ubuntu18.04或Ubuntu20.04
安装依赖
1 sudo apt-get update && sudo apt-get install binutils git git-lfs gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 bc gnutls-bin python3.8 python3-pip ruby device-tree-compiler lib32stdc++6 lib32z1 libncurses5-dev libtinfo5 scons genext2fs abootimg -y
配置git
1 git config --global user.name "yourname"
2 git config --global user.email "your-email-address"
3 git config --global credential.helper store
其中的信息应该为你在gitee的信息
安装repo
1 cd ~
2 curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > bin/repo
3 chmod a+x bin/repo
配置环境变量
1 vim ~/.bashrc
2 # 在最后一行添加: export PATH="~/bin/repo:$PATH"
3 :wq
4 source ~/.bashrc
配置地址
1 pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests
检查node版本
node -v
node版本必须在14以上!
源码获取
创建项目文件夹
1 cd ~
2 mkdir ohos
3 cd ohos
同步代码
1 repo init -u https://gitee.com/ohos_port/manifest -b fajita-OpenHarmony-3.2-Release --no-repo-verify
2 repo sync -c
3 repo forall -c 'git lfs pull'
编译准备
执行prebuild脚本
1 cd ~/ohos
2 ./build/prebuilts_download.sh
注释掉hap/build.sh内build_sdk函数内的第二个for循环,结果如下:
#!/bin/bash
# Copyright (c) 2022 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
CUR_PATH=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)
BASE_PATH=$(dirname ${CUR_PATH})
ROOT_PATH=$(cd ${CUR_PATH}/../../.. && pwd) && cd -
arg_project=""
arg_sdk_path=""
arg_build_sdk="false"
arg_help="0"
arg_url=""
arg_branch=""
arg_npm=""
arg_out_path="${ROOT_PATH}/out/hap"
arg_sign_tool="${ROOT_PATH}/developtools/hapsigner/dist"
arg_p7b=""
arg_apl="normal"
arg_feature="hos_normal_app"
arg_profile="UnsgnedReleasedProfileTemplate.json"
arg_bundle_name=""
function print_help() {
cat <<EOF
use assembleHap [options] <mainclass> [args...]
EOF
}
function clear_dir(){
if [ ! -d "$1" ]; then
mkdir -p $1
fi
}
function is_project_root(){
if [[ -f $1"/build-profile.json5" && -f $1"/hvigorfile.js" ]]; then
return 0
else
return 1
fi
}
function build_sdk() {
if [ -d ${ROOT_PATH}/out/sdk/packages/ohos-sdk/linux ]; then
echo "ohos-sdk exists."
return 0
fi
pushd ${ROOT_PATH}