fix: use random temp directory names for device installation paths

This commit is contained in:
cheliangzhao
2026-02-11 11:43:32 +08:00
parent bba88755f6
commit 01da810dfa
2 changed files with 39 additions and 20 deletions

View File

@@ -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 hvigorw assembleApp --mode project -p product=default -p buildMode=release --no-daemon
# Install to device (check actual output path in your project) # Install to device (check actual output path in your project)
hdc -t <UDID> shell "rm -rf /data/local/tmp/install && mkdir -p /data/local/tmp/install" # Use a random directory name to avoid conflicts with previous installations
hdc -t <UDID> file send <output_path>/signed /data/local/tmp/install INSTALL_DIR="/data/local/tmp/install_$(date +%s)"
hdc -t <UDID> shell "bm install -p /data/local/tmp/install/signed" hdc -t <UDID> shell "mkdir -p $INSTALL_DIR"
hdc -t <UDID> file send <output_path>/signed $INSTALL_DIR
hdc -t <UDID> shell "bm install -p $INSTALL_DIR/signed"
hdc -t <UDID> shell "rm -rf $INSTALL_DIR"
``` ```
**Note:** Build output path varies by project. Common paths: **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/`) 4. Find build output (check `outputs/default/signed/` or `outputs/project/bundles/signed/`)
5. Deploy to device: 5. Deploy to device:
```bash ```bash
hdc -t <UDID> shell "rm -rf /data/local/tmp/install && mkdir -p /data/local/tmp/install" INSTALL_DIR="/data/local/tmp/install_$(date +%s)"
hdc -t <UDID> file send <output_path>/signed /data/local/tmp/install hdc -t <UDID> shell "mkdir -p $INSTALL_DIR"
hdc -t <UDID> shell "bm install -p /data/local/tmp/install/signed" hdc -t <UDID> file send <output_path>/signed $INSTALL_DIR
hdc -t <UDID> shell "bm install -p $INSTALL_DIR/signed"
hdc -t <UDID> shell "rm -rf $INSTALL_DIR"
``` ```
6. Launch: `hdc -t <UDID> shell "aa start -a EntryAbility -b <bundleName>"` 6. Launch: `hdc -t <UDID> shell "aa start -a EntryAbility -b <bundleName>"`
7. Report success/failure with details 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 1. Read `AppScope/app.json5` to get bundleName
2. Push existing build output to device: 2. Push existing build output to device:
```bash ```bash
hdc -t <UDID> shell "rm -rf /data/local/tmp/install && mkdir -p /data/local/tmp/install" INSTALL_DIR="/data/local/tmp/install_$(date +%s)"
hdc -t <UDID> file send <output_path>/signed /data/local/tmp/install hdc -t <UDID> shell "mkdir -p $INSTALL_DIR"
hdc -t <UDID> shell "bm install -p /data/local/tmp/install/signed" hdc -t <UDID> file send <output_path>/signed $INSTALL_DIR
hdc -t <UDID> shell "bm install -p $INSTALL_DIR/signed"
hdc -t <UDID> shell "rm -rf $INSTALL_DIR"
``` ```
3. Launch: `hdc -t <UDID> shell "aa start -a EntryAbility -b <bundleName>"` 3. Launch: `hdc -t <UDID> shell "aa start -a EntryAbility -b <bundleName>"`
4. Report success/failure with details 4. Report success/failure with details
@@ -249,14 +256,18 @@ hdc -t <UDID> shell "whoami" # Test connection
### Push and Install ### Push and Install
```bash ```bash
# Clear device directory # Create random temp directory on device
hdc -t <UDID> shell "rm -rf /data/local/tmp/install && mkdir -p /data/local/tmp/install" INSTALL_DIR="/data/local/tmp/install_$(date +%s)"
hdc -t <UDID> shell "mkdir -p $INSTALL_DIR"
# Push signed bundles # Push signed bundles
hdc -t <UDID> file send path/to/signed /data/local/tmp/install hdc -t <UDID> file send path/to/signed $INSTALL_DIR
# Install all HAP/HSP in directory # Install all HAP/HSP in directory
hdc -t <UDID> shell "bm install -p /data/local/tmp/install/signed" hdc -t <UDID> shell "bm install -p $INSTALL_DIR/signed"
# Clean up temp directory
hdc -t <UDID> shell "rm -rf $INSTALL_DIR"
``` ```
### Verify and Launch ### Verify and Launch

View File

@@ -61,20 +61,24 @@ If no device found:
### Step 2: Push Files to Device ### Step 2: Push Files to Device
```bash ```bash
# Clear and create installation directory on device # Create random temp directory on device
hdc -t <UDID> shell "rm -rf /data/local/tmp/app_install && mkdir -p /data/local/tmp/app_install" INSTALL_DIR="/data/local/tmp/install_$(date +%s)"
hdc -t <UDID> shell "mkdir -p $INSTALL_DIR"
# Push signed HAP/HSP files # Push signed HAP/HSP files
hdc -t <UDID> file send outputs/default/signed /data/local/tmp/app_install hdc -t <UDID> file send outputs/default/signed $INSTALL_DIR
``` ```
### Step 3: Install Application ### Step 3: Install Application
```bash ```bash
# Install all HAP/HSP from directory # Install all HAP/HSP from directory
hdc -t <UDID> shell "bm install -p /data/local/tmp/app_install/signed" hdc -t <UDID> shell "bm install -p $INSTALL_DIR/signed"
# Expected output: "install bundle successfully." # Expected output: "install bundle successfully."
# Clean up temp directory
hdc -t <UDID> shell "rm -rf $INSTALL_DIR"
``` ```
### Step 4: Verify and Launch ### 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)}" DEVICE_ID="${1:-$(hdc list targets | head -1)}"
SIGNED_PATH="${2:-outputs/default/signed}" SIGNED_PATH="${2:-outputs/default/signed}"
BUNDLE_NAME="${3:-}" BUNDLE_NAME="${3:-}"
REMOTE_PATH="/data/local/tmp/app_install" REMOTE_PATH="/data/local/tmp/install_$(date +%s)"
if [ -z "$DEVICE_ID" ]; then if [ -z "$DEVICE_ID" ]; then
echo "Error: No device found. Connect a device or specify UDID as first argument." echo "Error: No device found. Connect a device or specify UDID as first argument."
@@ -107,9 +111,10 @@ fi
echo "Device: $DEVICE_ID" echo "Device: $DEVICE_ID"
echo "Source: $SIGNED_PATH" echo "Source: $SIGNED_PATH"
echo "Remote: $REMOTE_PATH"
# === Clear remote directory === # === Create remote directory ===
hdc -t "$DEVICE_ID" shell "rm -rf $REMOTE_PATH && mkdir -p $REMOTE_PATH" hdc -t "$DEVICE_ID" shell "mkdir -p $REMOTE_PATH"
# === Push signed files === # === Push signed files ===
hdc -t "$DEVICE_ID" file send "$SIGNED_PATH" "$REMOTE_PATH" 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")" BASENAME="$(basename "$SIGNED_PATH")"
hdc -t "$DEVICE_ID" shell "bm install -p $REMOTE_PATH/$BASENAME" hdc -t "$DEVICE_ID" shell "bm install -p $REMOTE_PATH/$BASENAME"
# === Clean up ===
hdc -t "$DEVICE_ID" shell "rm -rf $REMOTE_PATH"
echo "" echo ""
echo "Installation complete!" echo "Installation complete!"