Skip to content

Instantly share code, notes, and snippets.

@jevakallio
Last active August 13, 2026 17:53
Show Gist options
  • Select an option

  • Save jevakallio/452c54ef613792f25e45663ab2db117b to your computer and use it in GitHub Desktop.

Select an option

Save jevakallio/452c54ef613792f25e45663ab2db117b to your computer and use it in GitHub Desktop.
`adb pull` from app data directory without root access

TL;DR;

com.package.name is your app identifier, and the file path is relative to the app user's home directory, e.g. '/data/user/0/com.package.name.

adb shell run-as com.package.name cp relative/path/file.ext /sdcard
adb pull /sdcard/file.ext

See long explanation below.

Problem

Trying to adb pull files from our app's directory fails with Permission denied, because the adb user doesn't have access to the home directory.

adb pull /data/user/0/com.package.name/file.ext

Error:

adb: error: failed to stat remote object '/data/user/0/com.package.name/file.ext': Permission denied

You can try to run adb as root first:

adb root

But on a non-rooted device, this fails with:

adbd cannot run as root in production builds`

Here's a workaround on how to download a file from the app data directory using run-as.

Long version

This explains the solution step by step.

Start a shell session on the device. All following commands will be executed in the shell session on your device.

adb shell

Assuming our app identifier is com.package.name, the app data directory is at /data/user/0/com.package.name.

You can try to list files in that directory:

ls /data/user/0/com.package.name

This should result in error:

ls: /data/user/0/com.package.name/: Permission denied

However, you can run a command using the com.package.name application identity with the run-as command

run-as com.package.name ls /data/user/0/com.package.name/

You should now see a directory listing, and you can find the file you want, and copy it to a directory on your device that doesn't require root access, e.g. /sdcard:

run-as com.package.name cp /data/user/0/com.package.name/file.ext /sdcard

We can then exit the adb shell:

exit

Back at our own computer, we can adb pull the file:

adb pull /sdcard/file.ext
@mdkawser43589148-bot

Copy link
Copy Markdown

+880 1741-449179

@SuggonM

SuggonM commented Aug 13, 2026

Copy link
Copy Markdown

You don't really need to cp to the shared storage. You can directly print the data to stdout and redirect that output to a file on the PC. Another tip: use adb exec-out instead of adb shell for printing binary data.

adb exec-out "run-as com.debuggable.app cat files/path/to/image.png" > image.png

In my case, I wanted to copy the app's entire scoped directory. So packing it up into a single tape archive:

adb exec-out "run-as com.debuggable.app tar -cz ." > app.tar.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment