# 安装失败，UID 变更：包 com.example.app 在 /data/data/com.example.app 上的 UID 不匹配

- **ID:** `android/install-failed-uid-changed`
- **领域:** android
- **类别:** install_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

应用数据目录保留了之前安装的陈旧 UID，导致在卸载后未清除数据的情况下重新安装时 UID 不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Android 8.0 | active | — | — |
| Android 9 | active | — | — |
| Android 10 | active | — | — |
| Android 11 | active | — | — |
| Android 12 | active | — | — |
| Android 13 | active | — | — |
| Android 14 | active | — | — |
| Android 15 | active | — | — |

## 解决方案

1. ```
   Uninstall the app completely with adb uninstall com.example.app, then reinstall via adb install path/to/app.apk. This removes the stale data directory.
   ```
2. ```
   On a rooted device, run adb shell and execute: su -c 'rm -rf /data/data/com.example.app' to force-delete the directory, then reinstall.
   ```
3. ```
   If using Android Studio, go to Build > Clean Project, then Run > 'Uninstall All' from the device dropdown, then rebuild and deploy.
   ```

## 无效尝试

- **Reinstall the app without clearing data first via adb install -r** — The -r flag preserves app data, including the stale UID, so the mismatch persists. (95% 失败率)
- **Manually delete the package directory using adb shell rm -rf /data/data/com.example.app** — On production devices without root, the shell lacks permissions to delete system data directories. (80% 失败率)
- **Change the package name in the manifest to avoid the conflict** — This requires code changes and doesn't fix the root cause, leading to a different app identity. (90% 失败率)
