想了解更多关于开源的内容,请访问:
51CTO 开源基础软件社区
https://ost.51cto.com
由于Launcher自身原因,导致需要做2处改动才可进行源码编译构建。本步骤并非所有项目通用,如果新建的项目可以跳过本步骤,后续Launcher或工具更新后也不需要本步骤。
适配系统源码中NODE_HOME环境变量的配置,需要修改应用目录下hvigorw工具为最新。
文件位置:applications/standard/launcher/hvigorw
内容如下:
#!/bin/bash
# ----------------------------------------------------------------------------
# Hvigor startup script, version 1.0.0
#
# Required ENV vars:
# ------------------
# NODE_HOME - location of a Node home dir
# or
# Add /usr/local/nodejs/bin to the PATH environment variable
# ----------------------------------------------------------------------------
HVIGOR_APP_HOME="`pwd -P`"
HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
warn() {
echo ""
echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
}
error() {
echo ""
echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
}
fail() {
error "$@"
exit 1
}
# Determine node to start hvigor wrapper script
if [ -n "${NODE_HOME}" ];then
EXECUTABLE_NODE="${NODE_HOME}/bin/node"
if [ ! -x "$EXECUTABLE_NODE" ];then
fail "ERROR: NODE_HOME is set to an invalid directory,check $NODE_HOME\n\nPlease set NODE_HOME in your environment to the location where your nodejs installed"
fi
else
EXECUTABLE_NODE="node"
which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
fi
# Check hvigor wrapper script
if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
fi
# start hvigor-wrapper script
exec "${EXECUTABLE_NODE}" \
"${HVIGOR_WRAPPER_SCRIPT}" "$@"
由于系统编译应用目前不支持配置产品,所以需要把Launcher应用源码中有关pad的构建项删除。
文件位置:applications/standard/launcher/build-profile.json5
内容如下:
{
...
{
"name": "phone_launcher",
"srcPath": "./product/phone",
"targets": [
{
"name": "default",
"applyToProducts": [
"default",
],
},
],
},
{
"name": "launcher_settings",
"srcPath": "./feature/settings",
"targets": [
{
"name": "default",
"applyToProducts": [
"default",
],
},
],
}
],
}
文件位置:applications/standard/launcher/feature/settings/build-profile.json5。
内容如下:
{
"apiType": 'stageMode',
"buildOption": {
},
"targets": [
{
"name": "default",
}
],
"entryModules": ["phone_launcher"]
}
删除或注释系统中默认的Launcher应用hap包编译方式。
文件位置:applications/standard/hap/BUILD.gn 。
group("hap") {
deps = [
...
# "//applications/standard/hap:launcher_hap", // 直接删除或注释,不参与编译
# "//applications/standard/hap:launcher_settings_hap", // 直接删除或注释,不参与编译
...
]
}
在applications/standard/launcher目录中增加BUILD.gn文件。
内容如下:
import("//build/ohos.gni")
ohos_app("launcher_OS") {
part_name = "prebuilt_hap"
subsystem_name = "applications"
hap_name = "Launcher_OS"
certificate_profile = "./signature/launcher.p7b"
module_libs_dir = "entry"
module_install_dir = "app/com.ohos.launcher"
js_build_mode = "release"
build_level = "module"
assemble_type = "assembleHap"
}
说明:
在applications/standard/hap/ohos.build文件的module_list中增加launcher_OS模块编译。
{
"subsystem": "applications",
"parts": {
"prebuilt_hap": {
...
"module_list": [
...
"//applications/standard/launcher:launcher_OS",
...
]
}
}
}
执行源码编译指令。如果以下2个目录产物正确,则说明应用源码编译方式修改成功。
在out/rk3568/obj/applications/standard/launcher/launcher_OS目录中,会生成2个hap的编译产物。
在out/rk3568/packages/phone/system/app/com.ohos.launcher目录中,是实际系统环境中的hap包产物。
烧录系统验证功能。
Launcher正常启动:
系统应用目录文件正确:
想了解更多关于开源的内容,请访问:
51CTO 开源基础软件社区
https://ost.51cto.com