@@ -52,6 +52,13 @@ CERT_FILE="${CERT_FILE:-electerm_publish.cer}"
5252PROFILE_FILE=" ${PROFILE_FILE:- electermRelease.p7b} "
5353KEY_ALIAS=" ${KEY_ALIAS:- electerm_key} "
5454
55+ # Prebuilt HNP (busybox) for the 2in1 local terminal. The ~4 MB binary is
56+ # published as a GitHub release asset rather than committed to the repo, so the
57+ # build fetches it on demand. A local copy under hnp/<abi>/ takes precedence
58+ # (lets you build offline or test a custom build). Override the URL if needed.
59+ HNP_RELEASE_URL=" ${HNP_RELEASE_URL:- https:// github.com/ electerm/ electerm-harmony/ releases/ download/ hnp-electerm-shell-1.37.0/ electerm-shell.hnp} "
60+ HNP_PKG_NAME=" ${HNP_PKG_NAME:- electerm-shell.hnp} "
61+
5562# compatibleSdkVersion is deliberately separable from the compile SDK: the two
5663# answer different questions. compileSdkVersion is "which SDK built this"
5764# (whatever the local DevEco ships); compatibleSdkVersion is "what is allowed to
@@ -379,6 +386,23 @@ cd "${PROJECT_ROOT}"
379386
380387echo " ==> Building unsigned APP (${BUILD_MODE} ) ..."
381388
389+ # --- Stage HNP into the module dir (pre-assemble) ---------------------------
390+ # module.json5 declares hnpPackages, and hvigor may require the .hnp to exist
391+ # under the module's hnp/<abi>/ at assembleApp time. Copy it there now (the file
392+ # is gitignored). If hvigor packages it, the later injection is a harmless
393+ # duplicate; if it ignores HNP, the injection block still adds it. Either way
394+ # the build won't fail on a "missing HNP reference".
395+ MODULE_HNP_DIR=" ${PROJECT_ROOT} /entry/src/main/hnp/arm64-v8a"
396+ if compgen -G " ${HNP_SRC_ROOT} /*/*.hnp" > /dev/null; then
397+ mkdir -p " ${MODULE_HNP_DIR} "
398+ for hp in " ${HNP_SRC_ROOT} " /* /* .hnp; do
399+ cp " ${hp} " " ${MODULE_HNP_DIR} /"
400+ done
401+ echo " ✓ Staged HNP into ${MODULE_HNP_DIR} for assembleApp"
402+ else
403+ echo " • No local/downloaded HNP; hvigor HNP reference may be skipped"
404+ fi
405+
382406if [ " ${BUILD_MODE} " = " debug" ]; then
383407 " ${HVIGORW} " assembleApp -p product=default \
384408 -p buildMode=debug -p enableSignTask=false --no-daemon
427451
428452echo " ✓ Unsigned APP: ${UNSIGNED_APP} ($( du -h " ${UNSIGNED_APP} " | cut -f1) )"
429453
454+ # --- Inject HNP packages into the unsigned APP -------------------------------
455+ # hvigor / DevEco 26 does not package HNP declared in module.json5, so the .hnp
456+ # files under hnp/<abi>/ are injected manually: for each HAP inside the unsigned
457+ # .app we drop hnp/<abi>/<pkg>.hnp into it (the path the HNP installer expects),
458+ # then re-zip. app_packing_tool.jar --mode hap is the official alternative but it
459+ # demands re-supplying every HAP path (json/resources/ets/index/pack-info/…);
460+ # manual injection is equivalent and far less fragile.
461+ HNP_SRC_ROOT=" ${PROJECT_ROOT} /hnp"
462+
463+ # Download fallback: the ~4 MB .hnp is gitignored (published as a release asset
464+ # rather than committed), so CI / offline builders may not have it locally. If
465+ # no local .hnp is present, fetch the prebuilt release asset so the injection
466+ # below still runs. Non-fatal: a failed download just skips HNP and the 2in1
467+ # local terminal degrades to system HNP / toybox.
468+ if ! compgen -G " ${HNP_SRC_ROOT} /*/*.hnp" > /dev/null; then
469+ echo " ==> No local HNP packages; attempting download from release ..."
470+ if command -v curl > /dev/null 2>&1 ; then
471+ DL_DIR=" ${HNP_SRC_ROOT} /arm64-v8a"
472+ mkdir -p " ${DL_DIR} "
473+ if curl -fsSL " ${HNP_RELEASE_URL} " -o " ${DL_DIR} /${HNP_PKG_NAME} " ; then
474+ echo " ✓ Downloaded ${HNP_PKG_NAME} ($( du -h " ${DL_DIR} /${HNP_PKG_NAME} " | cut -f1) )"
475+ else
476+ echo " • Download failed (offline?); HNP injection will be skipped"
477+ rm -f " ${DL_DIR} /${HNP_PKG_NAME} "
478+ fi
479+ else
480+ echo " • curl unavailable; HNP injection will be skipped"
481+ fi
482+ fi
483+
484+ if [ -d " ${HNP_SRC_ROOT} " ] && compgen -G " ${HNP_SRC_ROOT} /*/*.hnp" > /dev/null; then
485+ echo " ==> Injecting HNP packages into unsigned APP ..."
486+ HNP_TMP=$( mktemp -d)
487+ hnp_injected=0
488+ echo " • Expanding ${UNSIGNED_APP} for HNP injection ..."
489+ unzip -q " ${UNSIGNED_APP} " -d " ${HNP_TMP} "
490+ while IFS= read -r hap; do
491+ hd=$( dirname " ${hap} " )
492+ bn=$( basename " ${hap} " .hap)
493+ wext=" ${hd} /${bn} "
494+ rm -rf " ${wext} "
495+ unzip -q " ${hap} " -d " ${wext} "
496+ rm -f " ${hap} "
497+ for abi_dir in " ${HNP_SRC_ROOT} " /* ; do
498+ [ -d " ${abi_dir} " ] || continue
499+ abi=$( basename " ${abi_dir} " )
500+ for hp in " ${abi_dir} " /* .hnp; do
501+ [ -f " ${hp} " ] || continue
502+ mkdir -p " ${wext} /hnp/${abi} "
503+ cp " ${hp} " " ${wext} /hnp/${abi} /"
504+ hnp_injected=$(( hnp_injected + 1 ))
505+ done
506+ done
507+ ( cd " ${wext} " && zip -r -q " ../${bn} .hap" . )
508+ rm -rf " ${wext} "
509+ done < <( find " ${HNP_TMP} " -name ' *.hap' -type f)
510+ # Re-zip the .app from the patched tree.
511+ mv " ${UNSIGNED_APP} " " ${UNSIGNED_APP} .prehnp"
512+ ( cd " ${HNP_TMP} " && zip -r -q " ${UNSIGNED_APP} " . )
513+ rm -f " ${UNSIGNED_APP} .prehnp"
514+ rm -rf " ${HNP_TMP} "
515+ echo " ✓ Injected ${hnp_injected:- 0} HNP package(s) into ${UNSIGNED_APP} "
516+ else
517+ echo " • No HNP packages found under ${HNP_SRC_ROOT} , skipping injection"
518+ fi
519+
430520# --- Sign the APP with hap-sign-tool.jar ------------------------------------
431521
432522echo " ==> Signing APP with hap-sign-tool.jar ..."
@@ -570,6 +660,17 @@ if [ "${JS_COUNT}" = "0" ]; then
570660 ERRORS=" ${ERRORS} \n ✗ No frontend JS in resfile"
571661fi
572662
663+ # The bundled HNP (electerm-shell.hnp) powers the 2in1 local terminal. Its
664+ # presence is informational here (private HNP only installs on 2in1), not a hard
665+ # gate — a missing .hnp simply means the local terminal falls back to the system
666+ # HNP / toybox on devices that have one.
667+ HNPS=$( find " ${HAP_DIR} " -name ' *.hnp' -type f 2> /dev/null)
668+ if [ -n " ${HNPS} " ]; then
669+ echo " ✓ HNP packages in HAP: $( printf ' %s\n' " ${HNPS} " | wc -l | tr -d ' ' ) file(s)"
670+ else
671+ echo " • (no .hnp in HAP — local terminal will rely on system HNP/toybox if present)"
672+ fi
673+
573674if [ -n " ${ERRORS} " ]; then
574675 echo -e " ::error::APP content verification failed:${ERRORS} "
575676 exit 1
0 commit comments