6.0 KiB
Device Installation Guide
Detailed guide for packaging and installing HarmonyOS applications to physical devices. This supplements the main SKILL.md with deeper troubleshooting, version verification, and an installation script.
Prerequisites
- hdc: HarmonyOS Device Connector (included in HarmonyOS SDK)
- Device: HarmonyOS device with USB debugging enabled
- Build Output: Signed HAP/HSP files from
hvigorw assembleApp
Verifying Build Outputs Before Installation
All HAP/HSP modules must have the same versionCode. Mismatched versions cause "version code not same" errors during installation.
Check versionCode of All Modules
# Using Python (cross-platform)
python3 -c "
import zipfile, json, glob
for f in glob.glob('outputs/default/signed/*.hsp'):
z = zipfile.ZipFile(f)
data = json.loads(z.read('module.json'))
print(f\"{f.split('/')[-1]}: versionCode = {data['app']['versionCode']}\")
"
# Using unzip + grep (Linux/macOS)
for f in outputs/default/signed/*.hsp; do
echo -n "$(basename $f): "
unzip -p "$f" module.json | grep -o '"versionCode":[0-9]*'
done
Identifying Problematic Modules
A module should be removed from the output before installation if:
- Module directory has no
src/folder (precompiled binary only) - Module not listed in
build-profile.json5modules array - Module versionCode differs from
AppScope/app.json5
rm outputs/default/signed/problematic-module-default-signed.hsp
Complete Installation Workflow
Step 1: Check Device Connection
hdc list targets
# Output: device UDID (e.g., 1234567890ABCDEF)
If no device found:
- Check USB connection
- Enable Developer Options on device: Settings > About > Tap build number 7 times
- Enable USB debugging: Settings > Developer options > USB debugging
- Run
hdc kill && hdc startto restart hdc server
Step 2: Push Files to Device
# Create random temp directory on device
INSTALL_DIR="/data/local/tmp/install_$(date +%s)"
hdc -t <UDID> shell "mkdir -p $INSTALL_DIR"
# Push signed HAP/HSP files
hdc -t <UDID> file send outputs/default/signed $INSTALL_DIR
Step 3: Install Application
# Install all HAP/HSP from directory
hdc -t <UDID> shell "bm install -p $INSTALL_DIR/signed"
# Expected output: "install bundle successfully."
# Clean up temp directory
hdc -t <UDID> shell "rm -rf $INSTALL_DIR"
Step 4: Verify and Launch
# Check package info
hdc -t <UDID> shell "bm dump -n <bundleName>"
# Launch application
hdc -t <UDID> shell "aa start -a EntryAbility -b <bundleName>"
Quick Installation Script
Save as install.sh (Linux/macOS) or run with Git Bash on Windows:
#!/bin/bash
# === Configuration ===
DEVICE_ID="${1:-$(hdc list targets | head -1)}"
SIGNED_PATH="${2:-outputs/default/signed}"
BUNDLE_NAME="${3:-}"
REMOTE_PATH="/data/local/tmp/install_$(date +%s)"
if [ -z "$DEVICE_ID" ]; then
echo "Error: No device found. Connect a device or specify UDID as first argument."
exit 1
fi
echo "Device: $DEVICE_ID"
echo "Source: $SIGNED_PATH"
echo "Remote: $REMOTE_PATH"
# === Create remote directory ===
hdc -t "$DEVICE_ID" shell "mkdir -p $REMOTE_PATH"
# === Push signed files ===
hdc -t "$DEVICE_ID" file send "$SIGNED_PATH" "$REMOTE_PATH"
# === Install ===
BASENAME="$(basename "$SIGNED_PATH")"
hdc -t "$DEVICE_ID" shell "bm install -p $REMOTE_PATH/$BASENAME"
# === Clean up ===
hdc -t "$DEVICE_ID" shell "rm -rf $REMOTE_PATH"
echo ""
echo "Installation complete!"
# === Optional: Launch app ===
if [ -n "$BUNDLE_NAME" ]; then
echo "Launching $BUNDLE_NAME..."
hdc -t "$DEVICE_ID" shell "aa start -a EntryAbility -b $BUNDLE_NAME"
fi
Usage:
# Auto-detect device, use default path
./install.sh
# Specify device UDID
./install.sh 1234567890ABCDEF
# Specify device and path
./install.sh 1234567890ABCDEF outputs/default/signed
# Specify device, path, and bundle name (auto-launch)
./install.sh 1234567890ABCDEF outputs/default/signed com.example.app
Build Output Structure
outputs/
└── {product}/ # e.g., default/
├── {project}-{product}-signed.app # Complete APP bundle
├── signed/
│ ├── entry-{product}-signed.hap # Main entry HAP
│ ├── feature-{product}-signed.hap # Feature HAP (if any)
│ └── *.hsp # Shared library modules
└── unsigned/
└── ... # Unsigned versions
Troubleshooting Details
Error: "version code not same"
Cause: Some HAP/HSP modules have different versionCode than others.
Solution:
- Use the version check commands above to find modules with different versionCode
- Remove those modules from signed directory before installation
- Usually caused by precompiled modules not in build-profile.json5
Error: "install parse profile prop check error"
Cause: Signature or profile configuration mismatch.
Solution:
- Check signing config in
build-profile.json5 - Ensure certificate and profile match
- Verify profile bundleName matches app.json5 bundleName
- Check certificate is not expired
Error: Device not found
Cause: Connection or hdc service issue.
Solution:
- Check USB cable connection
- Enable Developer Options: Settings > About > Tap build number 7 times
- Enable USB debugging: Settings > Developer options > USB debugging
- Restart hdc server:
hdc kill && hdc start - Try different USB port or cable
Error: "install failed due to older sdk version in the device"
Cause: Device system version is lower than app's minimum requirement.
Solution:
- Update device to latest system version
- Or lower
compatibleSdkVersioninbuild-profile.json5
Error: "signature verification failed"
Cause: Certificate issues.
Solution:
- Regenerate debug/release certificate in DevEco Studio
- Check certificate validity period
- Ensure using correct signing config for build type