| name | installing-and-managing-apps |
| description | 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". |
| license | Apache-2.0. See LICENSE for complete terms. |
| metadata | {"author":"Jaewoong Eum (skydoves)","keywords":["adb-install","pm-clear","pm-grant","pm-list-packages","force-stop","install-failed-user-restricted","install-failed-version-downgrade","install-multiple","baseline-profile","hermetic-test-reset"]} |
Installing and Managing Apps — adb install and pm
App lifecycle from the host. adb install ships an APK; pm is the on-device PackageManager front-end that lists, paths, clears, enables/disables, and grants permissions. The most common subtle bug in test scaffolding is using am force-stop to "reset" an app between tests — that command kills the process but leaves SharedPreferences, the Room DB, and files on disk. The hermetic equivalent is pm clear.
When to use this skill
- The user wants to install an APK from the host or push a debug build between every test run.
- The user asks "how do I reset the app's state between tests?" or sees stale data carry over from one test to the next.
- The user hits
INSTALL_FAILED_VERSION_DOWNGRADE, INSTALL_FAILED_USER_RESTRICTED, or signature mismatch errors.
- The user wants to grant all runtime permissions at install (
-g), or grant/revoke a single permission post-install.
- The user wants to list only third-party packages, find an APK on disk, or dump a Baseline Profile.
When NOT to use this skill
- The user wants to actually run instrumented tests against the installed app — use
../../tests/running-instrumented-tests-via-adb/SKILL.md.
- The user wants to choose a device or wait for boot — use
../../devices/connecting-to-devices/SKILL.md.
- The user wants the architecture / environment / authentication picture — use
../../architecture/understanding-adb-architecture/SKILL.md.
Prerequisites
- A connected device with state
device (see ../../devices/connecting-to-devices/SKILL.md).
- The APK(s) signed with a debug or release key the developer controls.
- For test APKs, the manifest sets
android:testOnly="true" (Gradle does this for androidTest builds) and install requires -t.
- For runtime permissions, the device runs API 23+.
Workflow
Patterns
Pattern: WRONG vs RIGHT — resetting app state between tests
adb shell am force-stop com.example.app
adb shell pm clear com.example.app
For test runs, the equivalent done by the runner itself is -e clearPackageData true to AndroidX Test Orchestrator — see ../../tests/running-instrumented-tests-via-adb/SKILL.md.
Pattern: WRONG vs RIGHT — installing an androidTest APK
adb install app-androidTest.apk
adb install -r -t -g app-androidTest.apk
Pattern: WRONG vs RIGHT — version downgrade after a debug install
adb install -r app-release.apk
adb install -r -d app-release.apk
adb uninstall com.example.app
adb install app-release.apk
Pattern: WRONG vs RIGHT — listing only third-party packages
adb shell pm list packages | grep -v 'com.android'
adb shell pm list packages -3
Mandatory rules
- MUST use
pm clear <pkg> to reset app state between tests; am force-stop does NOT clear data.
- MUST add
-t when installing any test APK (android:testOnly="true"); add -d when downgrading; add -g to grant all manifest runtime permissions.
- MUST use
adb install-multiple for split APKs (App Bundles). Single-APK install of one split fails with INSTALL_FAILED_INVALID_APK.
- MUST NOT assume
adb install of a freshly built debug APK will replace a release-signed install — signing-conflict errors require uninstall first.
- MUST NOT rely on
pm list packages | grep heuristics; use the documented filters (-3, -s, -d, -e, -u).
- PREFERRED: wire
clearPackageData true through Test Orchestrator (../../tests/running-instrumented-tests-via-adb/SKILL.md) instead of running pm clear manually before every test.
- PREFERRED: quote string arguments twice when they contain spaces or shell metacharacters — Platform Tools 23+ requires this (ssh-style quoting).
Verification
References
- ADB user guide (
pm install, pm uninstall, pm clear, pm grant, pm list packages): https://developer.android.com/tools/adb#pm
- AGP/Studio command-line testing (
am instrument and orchestrator wiring): https://developer.android.com/studio/test/command-line
- Baseline Profile dump via
cmd package dump-profiles: https://developer.android.com/topic/performance/baselineprofiles
- App Bundle / split APK install: https://developer.android.com/studio/build/build-variants
tasks/research/A2-adb-shell-commands.md — verbatim pm install/pm list/pm clear flag tables, force-stop vs pm clear distinction, ssh-style double-shell quoting since Platform Tools 23.
docs/CORPUS.md §I.10 — "force-stop does NOT clear data — pair with pm clear for hermetic reset."
- Sibling skills:
- High-level architecture:
../../architecture/understanding-adb-architecture/SKILL.md
- Connect a device:
../../devices/connecting-to-devices/SKILL.md
- Wireless ADB:
../../devices/connecting-over-wifi/SKILL.md
- Run tests via
am instrument (and Orchestrator clearPackageData): ../../tests/running-instrumented-tests-via-adb/SKILL.md
- Cross-set neighbours:
- Run instrumented tests with
AndroidJUnit4: ../../../instrumentation/runner/running-instrumented-tests-with-androidjunit4/SKILL.md
- Configure JUnit4 on Android:
../../../jvm-tests/runner/configuring-junit4-on-android/SKILL.md
- Source-set strategy:
../../../fundamentals/strategies/organizing-test-source-sets/SKILL.md