想了解更多关于开源的内容,请访问:
51CTO 开源基础软件社区
https://ost.51cto.com
删除或注释系统中默认的Launcher应用hap包编译方式。
文件位置:applications/standard/hap/BUILD.gn
group("hap") {
deps = [
...
# "//applications/standard/hap:launcher_hap", // 直接删除或注释,不参与编译
# "//applications/standard/hap:launcher_settings_hap", // 直接删除或注释,不参与编译
...
]
}
在applications/standard/launcher/product/phone目录中增加BUILD.gn文件。
内容如下:
import("//build/ohos.gni")
ohos_hap("launcher_hap") {
hap_profile = "src/main/module.json"
deps = [
":launcher_js_assets",
":launcher_resources",
]
certificate_profile = "../../signature/launcher.p7b"
hap_name = "Launcher_OS"
part_name = "prebuilt_hap"
subsystem_name = "applications"
js_build_mode = "release"
module_install_dir = "app/com.ohos.launcher"
}
ohos_js_assets("launcher_js_assets") {
ets2abc = true
source_dir = "src/main/ets"
}
ohos_resources("launcher_resources") {
sources = [ "src/main/resources", "../../common/src/main/resources" ]
deps = [ ":launcher_app_profile" ]
hap_profile = "src/main/module.json"
}
ohos_app_scope("launcher_app_profile") {
app_profile = "../../AppScope/app.json"
sources = [ "../../AppScope/resources" ]
}
说明:
在applications/standard/launcher/feature/settings目录中增加BUILD.gn文件。
内容如下:
import("//build/ohos.gni")
ohos_hap("launcher_settings_hap") {
hap_profile = "src/main/module.json"
deps = [
":launcher_settings_js_assets",
":launcher_settings_resources",
]
certificate_profile = "../../signature/launcher.p7b"
hap_name = "Launcher_Settings_OS"
part_name = "prebuilt_hap"
subsystem_name = "applications"
js_build_mode = "release"
module_install_dir = "app/com.ohos.launcher"
}
ohos_js_assets("launcher_settings_js_assets") {
ets2abc = true
source_dir = "src/main/ets"
}
ohos_resources("launcher_settings_resources") {
sources = [ "src/main/resources", "../../common/src/main/resources" ]
deps = [ ":launcher_settings_app_profile" ]
hap_profile = "src/main/module.json"
}
ohos_app_scope("launcher_settings_app_profile") {
app_profile = "../../AppScope/app.json"
sources = [ "../../AppScope/resources" ]
}
说明:
因为系统编译只可读取json后缀的配置文件,所以需要把应用源码中的app.json5和module.json5文件复制,并改名为app.json和module.json文件。
复制applications/standard/launcher/AppScope/app.json5文件为app.json。
复制applications/standard/launcher/product/phone/src/main/module.json5文件为module.json。
复制applications/standard/launcher/feature/settings/src/main/module.json5文件为module.json。
在applications/standard/hap/ohos.build文件module_list中增加launcher_hap模块和launcher_settings_hap模块编译。
{
"subsystem": "applications",
"parts": {
"prebuilt_hap": {
...
"module_list": [
...
"//applications/standard/launcher/product/phone:launcher_hap",
"//applications/standard/launcher/feature/settings:launcher_settings_hap",
...
]
}
}
}
修改预编译配置build/prebuilts_download_config.json文件,把launcher依赖增加到npm_install_path列表中。
{
"prebuilts_download_dir": "../OpenHarmony_canary_prebuilts",
"npm_install_path": [
"developtools/ace_ets2bundle/compiler",
"developtools/ace_js2bundle/ace-loader",
"third_party/jsframework",
"arkcompiler/ets_frontend/ts2panda",
"arkcompiler/ets_frontend/legacy_bin/api8",
"interface/sdk-js/build-tools",
"applications/standard/launcher/common",
"applications/standard/launcher/feature/appcenter",
"applications/standard/launcher/feature/bigfolder",
"applications/standard/launcher/feature/form",
"applications/standard/launcher/feature/gesturenavigation",
"applications/standard/launcher/feature/numbadge",
"applications/standard/launcher/feature/pagedesktop",
"applications/standard/launcher/feature/recents",
"applications/standard/launcher/feature/smartdock",
"applications/standard/launcher/feature/settings",
"applications/standard/launcher/product/phone"
],
...
}
执行预编译指令。
bash build/prebuilts_download.sh --skip-ssl
可以在应用源码中看到应用内的依赖已经被正确的加载。
执行源码编译指令。如果以下2个目录产物正确,则说明应用源码编译方式修改成功。
在out/rk3568/obj/applications/standard/launcher目录中,会生成2个hap的编译产物。
在out/rk3568/packages/phone/system/app/com.ohos.launcher目录中,是实际系统环境中的hap包产物。
烧录系统验证功能。
Launcher正常启动:
系统应用目录文件正确:
想了解更多关于开源的内容,请访问:
51CTO 开源基础软件社区
https://ost.51cto.com