diff --git a/harmonyos-build-deploy/SKILL.md b/harmonyos-build-deploy/SKILL.md index 1b9987b..b825e3d 100644 --- a/harmonyos-build-deploy/SKILL.md +++ b/harmonyos-build-deploy/SKILL.md @@ -36,9 +36,12 @@ Complete workflow for building, cleaning, packaging, and installing HarmonyOS ap hvigorw assembleApp --mode project -p product=default -p buildMode=release --no-daemon # Install to device (check actual output path in your project) -hdc -t shell "rm -rf /data/local/tmp/install && mkdir -p /data/local/tmp/install" -hdc -t file send /signed /data/local/tmp/install -hdc -t shell "bm install -p /data/local/tmp/install/signed" +# Use a random directory name to avoid conflicts with previous installations +INSTALL_DIR="/data/local/tmp/install_$(date +%s)" +hdc -t shell "mkdir -p $INSTALL_DIR" +hdc -t file send /signed $INSTALL_DIR +hdc -t shell "bm install -p $INSTALL_DIR/signed" +hdc -t shell "rm -rf $INSTALL_DIR" ``` **Note:** Build output path varies by project. Common paths: @@ -61,9 +64,11 @@ Delegate to subagent with the following steps: 4. Find build output (check `outputs/default/signed/` or `outputs/project/bundles/signed/`) 5. Deploy to device: ```bash - hdc -t shell "rm -rf /data/local/tmp/install && mkdir -p /data/local/tmp/install" - hdc -t file send /signed /data/local/tmp/install - hdc -t shell "bm install -p /data/local/tmp/install/signed" + INSTALL_DIR="/data/local/tmp/install_$(date +%s)" + hdc -t shell "mkdir -p $INSTALL_DIR" + hdc -t file send /signed $INSTALL_DIR + hdc -t shell "bm install -p $INSTALL_DIR/signed" + hdc -t shell "rm -rf $INSTALL_DIR" ``` 6. Launch: `hdc -t shell "aa start -a EntryAbility -b "` 7. Report success/failure with details @@ -75,9 +80,11 @@ Delegate to subagent with the following steps: 1. Read `AppScope/app.json5` to get bundleName 2. Push existing build output to device: ```bash - hdc -t shell "rm -rf /data/local/tmp/install && mkdir -p /data/local/tmp/install" - hdc -t file send /signed /data/local/tmp/install - hdc -t shell "bm install -p /data/local/tmp/install/signed" + INSTALL_DIR="/data/local/tmp/install_$(date +%s)" + hdc -t shell "mkdir -p $INSTALL_DIR" + hdc -t file send /signed $INSTALL_DIR + hdc -t shell "bm install -p $INSTALL_DIR/signed" + hdc -t shell "rm -rf $INSTALL_DIR" ``` 3. Launch: `hdc -t shell "aa start -a EntryAbility -b "` 4. Report success/failure with details @@ -249,14 +256,18 @@ hdc -t shell "whoami" # Test connection ### Push and Install ```bash -# Clear device directory -hdc -t shell "rm -rf /data/local/tmp/install && mkdir -p /data/local/tmp/install" +# Create random temp directory on device +INSTALL_DIR="/data/local/tmp/install_$(date +%s)" +hdc -t shell "mkdir -p $INSTALL_DIR" # Push signed bundles -hdc -t file send path/to/signed /data/local/tmp/install +hdc -t file send path/to/signed $INSTALL_DIR # Install all HAP/HSP in directory -hdc -t shell "bm install -p /data/local/tmp/install/signed" +hdc -t shell "bm install -p $INSTALL_DIR/signed" + +# Clean up temp directory +hdc -t shell "rm -rf $INSTALL_DIR" ``` ### Verify and Launch diff --git a/harmonyos-build-deploy/references/device-installation.md b/harmonyos-build-deploy/references/device-installation.md index 4aa9a62..5e98525 100644 --- a/harmonyos-build-deploy/references/device-installation.md +++ b/harmonyos-build-deploy/references/device-installation.md @@ -61,20 +61,24 @@ If no device found: ### Step 2: Push Files to Device ```bash -# Clear and create installation directory on device -hdc -t shell "rm -rf /data/local/tmp/app_install && mkdir -p /data/local/tmp/app_install" +# Create random temp directory on device +INSTALL_DIR="/data/local/tmp/install_$(date +%s)" +hdc -t shell "mkdir -p $INSTALL_DIR" # Push signed HAP/HSP files -hdc -t file send outputs/default/signed /data/local/tmp/app_install +hdc -t file send outputs/default/signed $INSTALL_DIR ``` ### Step 3: Install Application ```bash # Install all HAP/HSP from directory -hdc -t shell "bm install -p /data/local/tmp/app_install/signed" +hdc -t shell "bm install -p $INSTALL_DIR/signed" # Expected output: "install bundle successfully." + +# Clean up temp directory +hdc -t shell "rm -rf $INSTALL_DIR" ``` ### Step 4: Verify and Launch @@ -98,7 +102,7 @@ Save as `install.sh` (Linux/macOS) or run with Git Bash on Windows: DEVICE_ID="${1:-$(hdc list targets | head -1)}" SIGNED_PATH="${2:-outputs/default/signed}" BUNDLE_NAME="${3:-}" -REMOTE_PATH="/data/local/tmp/app_install" +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." @@ -107,9 +111,10 @@ fi echo "Device: $DEVICE_ID" echo "Source: $SIGNED_PATH" +echo "Remote: $REMOTE_PATH" -# === Clear remote directory === -hdc -t "$DEVICE_ID" shell "rm -rf $REMOTE_PATH && mkdir -p $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" @@ -118,6 +123,9 @@ hdc -t "$DEVICE_ID" file send "$SIGNED_PATH" "$REMOTE_PATH" 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!"