Skip to content

实现 arm64 HarmonyOS 上的本地构建 - #64

Merged
hackeris merged 19 commits into
winehua:masterfrom
SwimmingTiger:build-on-ohos-2
Aug 17, 2026
Merged

实现 arm64 HarmonyOS 上的本地构建#64
hackeris merged 19 commits into
winehua:masterfrom
SwimmingTiger:build-on-ohos-2

Conversation

@SwimmingTiger

@SwimmingTiger SwimmingTiger commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

构建方法:

  1. 下载并解压鸿蒙原生 command-line-tools: https://github.com/SwimmingTiger/command-line-tools/releases

  2. 下载并解压鸿蒙原生 llvm-mingw: https://github.com/SwimmingTiger/llvm-mingw/releases

  3. 安装Harmonybrew并通过brew命令安装依赖包:

brew install java python3 node ohos-sdk devel-base llvm-gcc-compat cmake uname-is-linux
  1. 创建pyenv并安装python依赖包:
python3 -m venv ~/pyenv
source ~/pyenv/bin/activate
pip3 install pyyaml mako packaging

备注:mesa那个缺少mako的报错不仅要安装mako,还得安装packaging才能解决。
还有一些别的不记得了,可以看报错再装 (190598 修复了缺少pyyaml的报错不可见)

  1. 创建 build-profile.json5
cp build-profile.json5.example build-profile.json5
  1. 设置编译工具链路径并开始构建:
export TOOL_HOME=/path/to/command-line-tools
export LLVM_MINGW=/path/to/llvm-mingw-20260718-ucrt-ohos-arm64

# 别忘了加载pyenv,每次打开新终端都要重新加载
source ~/pyenv/bin/activate

./build-on-ohos.sh

已经测试过可以构建出可用的hap,并且签名功能也正常(在build-profile.json5配置正确的证书就可以)。


build-on-ohos.sh 会避免使用 brew 的 cat 和 cp 命令,它们产生的具体问题见 build-on-ohos.sh 的注释:

相关issue:


构建结果:

image

SwimmingTiger and others added 19 commits August 16, 2026 12:02
根本原因:`threading.Event` 一旦 `set()` 永久保持。当所有初始扫描任务恰好先完成时,`_pending` 短暂归零触发了 `_event.set()`,但主线程此时还在 `for` 循环中阻塞于 `scan_slots.acquire()`,未提交完所有顶层目录。等到主线程到达 `tracker.wait()` 时 event 早已 set,立即返回,后续条目被遗漏。

修复:增加了 `_all_submitted` 标志。只有同时满足「所有顶层条目已提交」和「所有扫描任务已完成」两个条件时,才设置 event 放行 `wait()`。
调整 PATH 让系统 cat 和 cp 命令优先级更高,避免使用 brew 的 cat 和 cp 命令

brew cat 会导致 cat: -: Broken pipe 报错,详见: https://atomgit.com/org/Harmonybrew/discussions/6

brew cp 会导致 libffi.so.8 复制失败并得到损坏的文件,报错如下:
cp: error deallocating '……/WineHua/entry/libs/arm64-v8a/libffi.so.8': Permission denied
并且报错后cp依然以状态码0退出,所以编译不会失败,但最终得到的hap会闪退。
比如 scripts/build_native.sh 的以下错误信息就会被 $() 吞掉:

err "python3 with PyYAML is required. Install: pip3 install pyyaml"
@hackeris
hackeris merged commit 734deed into winehua:master Aug 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants