Loading...
Loading...
Use this skill to move files between host and device with `adb pull` and `adb push`, including the modern `-z` (compression), `-Z` (no compression), `--sync`, and `-a` (preserve attrs) flags. Covers the path-permission rules — `/data/local/tmp/` is freely writable, `/sdcard/` (alias `/storage/emulated/0/`) is shell-writable with scoped-storage rules on API 30+, `/data/data/<pkg>/` requires `run-as <pkg>` on debuggable builds, and `/sdcard/Android/data/<pkg>/files/` is package-owned but pullable. Includes `adb shell run-as <pkg> cat <path>` for text grabs, `adb exec-out run-as <pkg> tar cf - <path> | tar xf -` for binary-clean directory grabs, the `connected_android_test_additional_output/` Gradle output dir, and the `androidx.test:services` `useTestStorageService` flag for the modern artefact-collection API. If the user mentions "adb pull permission denied data data", "run-as", "scoped storage shell", "tar through adb", "test storage service", or "exec-out vs shell for binary", use this skill.
npx skill4agent add skydoves/android-testing-skills extracting-test-artifactspullandroidx.test:servicesTestStorage../../automation/scripting-adb-for-ci/SKILL.mdadb pull /data/data/com.example/databases/main.dbrun-asexec-out-z brotli/sdcard/Android/data/com.example/files/screenshots/TestStorage../../capture/capturing-screenshots-and-screenrecord/SKILL.md../../observability/extracting-logs-with-logcat/SKILL.md../../apps/installing-and-managing-apps/SKILL.md../../control/injecting-input-and-state/SKILL.md../../automation/scripting-adb-for-ci/SKILL.mdadb get-statedevice../../devices/connecting-to-devices/SKILL.mdrun-asandroid:debuggable="true"debug-z brotlizstdTestStorageandroidx.test:services-e useTestStorageService trueam instrument"Unlike thecommand, which only copies an APK file to a specific location, theinstallandpullcommands let you copy arbitrary directories and files to any location in a device." — developer.android.com/tools/adbpush
adb pull <remote> [<local>] # device → host (defaults to cwd)
adb push <local> <remote> # host → devicepush [--sync] [-z ALGORITHM] [-Z] LOCAL... REMOTE
pull [-a] [-z ALGORITHM] [-Z] REMOTE... LOCAL| Flag | Meaning |
|---|---|
| Enable compression. |
| Disable compression. |
| Only push files with different timestamps — fast incremental updates. |
| Preserve file timestamp and mode. |
| Dry-run. |
| Suppress progress messages. |
adb pull -p-q-padb pull| Path | adb shell writable? | |
|---|---|---|
| Yes | Yes |
| Yes (scoped storage rules on API 30+) | Yes |
| Only via | Only via |
| Package-owned, scoped storage | Yes for the owning package, and yes for |
/data/local/tmp/shelladbu0_aXXshellchmod 0644/data/local/tmp/0771/sdcard//storage/emulated/0//storage/self/primary/shelladb push /sdcard/...adb pull /sdcard/.../data/data/<pkg>/run-as0700adb pull /data/data/com.example/...run-as <pkg>adb rootuserdebugeng../../automation/scripting-adb-for-ci/SKILL.md/sdcard/Android/data/<pkg>/files/Context.getExternalFilesDir(null)adb shell# Inside the test app:
val out = File(context.getExternalFilesDir(null), "screenshots/fail.png")# From CI:
adb pull /sdcard/Android/data/com.example/files/screenshots/fail.png ./run-asrun-as <pkg>android:debuggable="true"debugadb shell run-as <pkg> <cmd>adb shell run-as com.example.app cat databases/main.db > main.dbexec-outexec-outtar\nexec-outtaradb exec-out run-as com.example.app tar cf - databases/ \
| tar xf - -C ./pulledtar cf -tar xf -./pulled/adb exec-out run-as com.example.app cat databases/main.db > main.dbexec-outadb shell run-as com.example.app ls -lR files/run-as--user N| Path | Origin |
|---|---|
| Gradle's standard "additional output" sink. The instrumentation runner pulls anything declared via |
| JUnit-style XML test results — ingested directly by Jenkins/GHA/etc. |
| HTML test report. |
module/build/reports/androidTests/connected/module/build/outputs/androidTest-results/connected/TestStorage/sdcard/...androidx.test.services.storage.TestStorageuseTestStorageService// dependencies
androidTestImplementation("androidx.test:runner:1.7.0")
androidTestUtil("androidx.test.services:test-services:1.6.0")// am instrument args (or Gradle: testInstrumentationRunnerArguments)
adb shell am instrument -w -r \
-e useTestStorageService true \
com.example.test/androidx.test.runner.AndroidJUnitRunnerval storage = androidx.test.platform.io.PlatformTestStorageRegistry.getInstance()
storage.openOutputFile("screenshots/fail-${test.methodName}.png").use { out ->
out.write(pngBytes)
}TestStorage/sdcard/connectedAndroidTestapp/build/outputs/connected_android_test_additional_output/Class.methodclearPackageData: 'true'/sdcard/googletest/test_outputfiles/...adb pull /data/data/<pkg>/...# WRONG
adb pull /data/data/com.example/databases/main.db
# adb: error: failed to stat remote object '/data/data/com.example/databases/main.db': Permission denied
# WRONG because: /data/data/<pkg>/ is owned by the app UID with mode 0700. The shell user
# cannot traverse it. run-as solves this on debuggable builds.# RIGHT — run-as + exec-out + cat for a binary-clean grab
adb exec-out run-as com.example cat databases/main.db > main.db
file main.db # → "SQLite 3.x database"adb exec-out run-as com.example tar cf - databases/ | tar xf - -C ./pulledadb shell run-as <pkg> cat <binary># WRONG (on Windows / certain CI hosts)
adb shell run-as com.example cat databases/main.db > main.db
# WRONG because: `adb shell` allocates a PTY and translates LF to CRLF on stdout. SQLite
# headers and other binary content get corrupted. The pulled DB fails to open.# RIGHT — exec-out is binary-clean
adb exec-out run-as com.example cat databases/main.db > main.db// In production / test code
val out = File(context.getExternalFilesDir(null), "captures/${name}.png")
out.outputStream().use { it.write(bitmapBytes) }# CI script
adb pull /sdcard/Android/data/com.example/files/captures/ ./artifacts/run-as/sdcard/Android/data/<pkg>/files/adb shelladb push --sync -z brotli ./fixtures/ /sdcard/fixtures/--sync-z brotliTestStorageclass CaptureOnFailureRule : TestWatcher() {
override fun failed(e: Throwable, description: Description) {
val storage = PlatformTestStorageRegistry.getInstance()
val name = "${description.className}.${description.methodName}"
storage.openOutputFile("captures/$name.png").use { out ->
out.write(captureScreenshotPng())
}
}
}connectedAndroidTestapp/build/outputs/connected_android_test_additional_output/<flavor><Variant>/connected/<device>/captures/<name>.pngadb exec-out run-as <pkg> cat <path>adb shell run-as ...adb exec-out run-as <pkg> tar cf - <dir> | tar xf -/data/data/<pkg>/adb pullrun-asrun-asrun-as/sdcard/Android/data/<pkg>/files/Context.getExternalFilesDir(null)/sdcard/<dir>/TestStorage-e useTestStorageService trueandroidx.test:services/sdcard/...connected_android_test_additional_output/adb pull -p-qadb pull/data/data/<pkg>/...run-aspullshell--sync -z brotliclearPackageData: 'true'useTestStorageService: 'true'adb pull /data/data/<pkg>/...run-asadb exec-outadb shellContext.getExternalFilesDir(...)/sdcard/Android/data/<pkg>/files//sdcard/<arbitrary>/app/build/outputs/connected_android_test_additional_output/**/*adb push --syncfileadb pull/data/data/<pkg>/...pullpushmodule/build/reports/androidTests/connected/module/build/outputs/androidTest-results/connected/Context.getExternalFilesDir()tasks/research/A3-adb-observability-automation.md../../architecture/understanding-adb-architecture/SKILL.md../../devices/connecting-to-devices/SKILL.mdadb get-state../../devices/connecting-over-wifi/SKILL.md../../apps/installing-and-managing-apps/SKILL.mdpm install../../tests/running-instrumented-tests-via-adb/SKILL.mdam instrumentuseTestStorageService../../control/injecting-input-and-state/SKILL.md../../capture/capturing-screenshots-and-screenrecord/SKILL.md../../observability/extracting-logs-with-logcat/SKILL.mdadb shell logcat -fadb pull../../automation/scripting-adb-for-ci/SKILL.md../../../instrumentation/runner/running-instrumented-tests-with-androidjunit4/SKILL.mdTestWatcherTestStorage../../../instrumentation/scenarios/launching-activities-with-activityscenario/SKILL.md../../../fundamentals/strategies/applying-testing-strategies/SKILL.md