Loading...
Loading...
Use this skill to install, uninstall, list, inspect, and reset Android apps via `adb install` (with `-r` reinstall, `-d` allow-downgrade, `-t` allow test packages, `-g` grant all runtime permissions, `--user` per-user install, `adb install-multiple` for split APKs) and the on-device `pm` tool (`pm list packages [-f|-d|-e|-s|-3|-i|-u]`, `pm path`, `pm clear`, `pm grant` / `pm revoke`, `pm enable` / `pm disable`, `pm uninstall [-k]`, `cmd package dump-profiles`). Calls out the canonical hermetic-reset pattern (`pm clear` wipes data; `am force-stop` does NOT) and the common install errors (`INSTALL_FAILED_USER_RESTRICTED`, `INSTALL_FAILED_VERSION_DOWNGRADE`, signing-conflict). Use when the user mentions "reset app between tests", `pm clear`, `am force-stop` confusion, install fails after debugger, split APK install, runtime permission grants, multi-user profile installs, or "how do I list third-party apps".
npx skill4agent add skydoves/android-testing-skills installing-and-managing-appsadb installpmadb installpmam force-stoppm clearINSTALL_FAILED_VERSION_DOWNGRADEINSTALL_FAILED_USER_RESTRICTED-g../../tests/running-instrumented-tests-via-adb/SKILL.md../../devices/connecting-to-devices/SKILL.md../../architecture/understanding-adb-architecture/SKILL.mddevice../../devices/connecting-to-devices/SKILL.mdandroid:testOnly="true"androidTest-tpm installadb install| Flag | Meaning |
|---|---|
| "Reinstall an existing app, keeping its data." Required when the package is already installed; without it |
| "Allow version code downgrade." Required when the new APK has a lower |
| "Allow test APKs to be installed." Required for any APK whose manifest carries |
| "Grant all permissions listed in the app manifest." Best for hermetic test runs. |
| Forward-lock the application (legacy DRM). Almost never needed today. |
| Install on the SD card / external storage (when device supports it). |
| Install for a specific user profile. Default: all users. |
| `--install-location 0 | 1 |
| Install on internal system memory. |
| Tag the install with an installer package name. |
| Patch-only install (only changed parts of the APK). |
| Streamed install; requires APK Signature Scheme v4 sidecar |
adb install -r app-debug.apk # ordinary reinstall
adb install -r -d app-debug.apk # allow downgrade
adb install -r -t -g app-androidTest.apk # test APK with all permissions granted
adb install -r -d --user current app-debug.apk # force foreground-user installadb install-multipleadb installadb install-multiple -r -t -g \
base-master.apk base-arm64_v8a.apk base-xxhdpi.apkpm clearam force-stopam force-stop <pkg>package/data/data/<pkg>pm clear <pkg>pm clearam force-stopadb shell pm clear com.example.appclearPackageData../../tests/running-instrumented-tests-via-adb/SKILL.mdpm list packagespm pathpm list packages [-f] [-d] [-e] [-s] [-3] [-i] [-u] [--user <id>] [<filter>]| Flag | Meaning |
|---|---|
| "See associated file." |
| "Filter to only show disabled packages." |
| "Filter to only show enabled packages." |
| "Filter to only show system packages." |
| "Filter to only show third-party packages." |
| "See the installer for the packages." |
| "Include uninstalled packages." |
| "The user space to query." |
adb shell pm list packages -3 | sort # all sideloaded apps
adb shell pm list packages -f com.example # APK paths for matching pkgs
adb shell pm path com.example.app # package:/data/app/.../base.apk
adb shell dumpsys package com.example.app | head -200 # detailed install/permission infopm grantpm revoke"Grant a permission to an app. On devices running Android 6.0 (API level 23) and higher, the permission can be any permission declared in the app manifest."
adb shell pm grant com.example.app android.permission.CAMERA
adb shell pm revoke com.example.app android.permission.CAMERA
adb shell pm reset-permissions # reset every app to defaults-gadb shell pm disable com.example.app # whole package
adb shell pm disable-user --user 0 com.example.app # per-user disable (preserves data)
adb shell pm enable com.example.app
adb shell pm enable com.example.app/.MyTestActivity # specific componentpm uninstall [-k] [--user <id>] [--versionCode <vc>] <package>-k--user <id>--versionCode <vc>adb uninstall com.example.app # equivalent to: pm uninstall <pkg>
adb shell pm uninstall -k com.example.app # uninstall but preserve data
adb shell pm uninstall --user 0 com.example.app # only from primary user"Starting in Android 7.0 (API level 24), the Android Runtime (ART) collects execution profiles for installed apps...thenadb shell cmd package dump-profiles <package>." The doc warns: "It is only possible to retrieve the execution profile filename if you have root access to the file system, for example, on an emulator." On user builds without root, useadb pull /data/misc/profman/<package>.prof.txtMacrobenchmark to extract the profile programmatically.androidx.benchmark
| Error | Cause | Fix |
|---|---|---|
| New APK's | Add |
| Multi-user device: the install user (typically the secondary or work profile) blocks installs. | |
| New APK signed with a different key than the installed one. | Uninstall first ( |
| APK has | Add |
| Tried to install one APK of a split set. | Use |
| Out of space. | |
"With Android Platform Tools 23 and higher,handles arguments the same way that theadbcommand does. ...ssh(1)is now an error ... To make the command work, quote twice, once for the local shell and once for the remote shell, as you do withadb shell setprop key 'two words'. For example,ssh(1)works because the local shell takes the outer level of quoting and the device still sees the inner level of quoting." Same rule applies for anyadb shell setprop key \"'two words'\"argument with spaces, special characters, or shell metacharacters.pm
# WRONG
adb shell am force-stop com.example.app
# Run next test...
# WRONG because: force-stop kills the process but leaves SharedPreferences,
# Room DB, files in /data/data/<pkg>, and cache. Tests that read any of those
# carry stale state into the next case. Flake follows.# RIGHT
adb shell pm clear com.example.app
# Run next test against fresh-install state.-e clearPackageData true../../tests/running-instrumented-tests-via-adb/SKILL.mdandroidTest# WRONG
adb install app-androidTest.apk
# adb: failed to install app-androidTest.apk: Failure [INSTALL_FAILED_TEST_ONLY:
# installPackageLI]
# WRONG because: any APK with android:testOnly="true" (every Gradle-built test
# APK) requires `-t`.# RIGHT
adb install -r -t -g app-androidTest.apk
# -r: reinstall keeping data (or overwriting); -t: allow test packages;
# -g: grant all runtime permissions for hermetic tests.# WRONG
adb install -r app-release.apk
# adb: failed to install app-release.apk: Failure [INSTALL_FAILED_VERSION_DOWNGRADE]
# WRONG because: the installed debug APK has a higher versionCode than the
# release APK being installed.# RIGHT
adb install -r -d app-release.apk # allow downgrade
# Or, when signature also changes:
adb uninstall com.example.app
adb install app-release.apk# WRONG
adb shell pm list packages | grep -v 'com.android'
# WRONG because: many third-party packages also have names containing
# "com.android" (e.g. third-party Android library demos), and Google's own
# pre-installed apps carry varied prefixes (com.google.android.*).# RIGHT
adb shell pm list packages -3
# `-3` filters to third-party (non-system) packages only.pm clear <pkg>am force-stop-tandroid:testOnly="true"-d-gadb install-multipleINSTALL_FAILED_INVALID_APKadb installpm list packages | grep-3-s-d-e-uclearPackageData true../../tests/running-instrumented-tests-via-adb/SKILL.mdpm clearadb install -r -t -g app-androidTest.apkSuccessadb shell pm path com.example.apppackage:/data/app/...base.apkadb shell pm clear com.example.appSuccessadb shell run-as com.example.app ls /data/data/com.example.appcache/code_cache/adb shell pm list packages -3 | grep com.example.appadb shell pm grant com.example.app android.permission.CAMERAadb shell dumpsys package com.example.app | grep CAMERAadb uninstall com.example.appSuccesspm list packages com.example-e clearPackageData truepm clear@Before@Afterpm installpm uninstallpm clearpm grantpm list packagesam instrumentcmd package dump-profilestasks/research/A2-adb-shell-commands.mdpm installpm listpm clearforce-stoppm cleardocs/CORPUS.mdpm clear../../architecture/understanding-adb-architecture/SKILL.md../../devices/connecting-to-devices/SKILL.md../../devices/connecting-over-wifi/SKILL.mdam instrumentclearPackageData../../tests/running-instrumented-tests-via-adb/SKILL.mdAndroidJUnit4../../../instrumentation/runner/running-instrumented-tests-with-androidjunit4/SKILL.md../../../jvm-tests/runner/configuring-junit4-on-android/SKILL.md../../../fundamentals/strategies/organizing-test-source-sets/SKILL.md