Adb / Uninstall Package Keep Data
Uninstall Package Keep Data
Use 'adb uninstall -k com.example.app' to remove an app while retaining data; useful for persistent state testing.
adb uninstall -k <com.example.app> adb uninstall -k <com.example.app> #!/bin/bash
# Uninstall Package Keep Data
adb uninstall -k {{com.example.app}} import subprocess
# Uninstall Package Keep Data
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"adb",
"uninstall",
"-k",
"<com.example.app>"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: adb not found. Please install it first.")
if __name__ == "__main__":
run_command() When To Use
Utilize this command when troubleshooting application stability issues that require repeated clean installs without losing user-generated data. It's particularly vital during regression tests or when fixing a bug affecting user data consistency in apps.
Pro Tip
Before using this command, ensure the app's data is not corrupted, as reinstalling could perpetuate latent issues. In some cases, reinstallation conflicts can arise if app versioning is misaligned.
Terminal Output
Expected runtime feedback
Package com.example.app successfully uninstalled.\nUser data preserved! Anatomy of Output
Understanding the result
Success Success Message Indicates the app was successfully uninstalled but its data remains intact.
Failure Failure Message Indicates an issue occurred, possibly related to insufficient permissions or device state.
Troubleshooting
Common pitfalls
Failure [DELETE_FAILED_INTERNAL_ERROR]
Solution: Check if the package manager has the necessary permissions or if the device is in a stable state.
device unauthorized
Solution: Ensure adb debugging is authorized on the device.
error: device offline
Solution: Verify that the device is properly connected and recognized by adb.
Command Breakdown
What each part is doing
-
adb - Base Command
- The executable that performs this operation. Here it runs Adb before the shell applies any redirect operators.
-
<com.example.app> - com.example.app
- The value supplied for com.example.app.
-
-k - Command Option
- Tool-specific option used by this command invocation.
How To Run
Execution path
- Step 1
Connect your Android device via USB and ensure USB debugging is enabled.
- Step 2
Run the command: `adb uninstall -k com.example.app`
- Step 3
Verify the package is removed while data is intact by checking with `adb shell pm list packages`.
Alternative Approaches
Comparable commands in other tools
Alternative system operations tools for the same job.
owut upgrade -V <version> -a "<htop vim>" Archivemount / Mount Archive Linux archivemount <path/to/archive> <path/to/mount_point> Warp Diag / Generate Zip System Info warp-diag Warp Diag / Generate Zip Debug Info Timestamped warp-diag --add-ts Chronyc / Start Chronyc Interactive Mode chronyc