As a brief note, today I tried to list the files in my Android application, which was running on a physical Android device — a Nexus 9 — with this adb shell
command:
adb shell com.alvinalexander.mybrowser ls /data/data/com.alvinalexander.mybrowser
When I did that, I got an Android/ADB “permission denied” error.
The short story is that a solution to this problem is to run the same command, but with the run-as
argument, like this:
adb shell run-as com.alvinalexander.mybrowser ls /data/data/com.alvinalexander.mybrowser
As a note to self, I confirmed this run-as
command again in February, 2022, while working on a Flutter app:
adb shell run-as com.valleyprogramming.myapp ls /data/data/com.valleyprogramming.myapp/app_flutter
More information
The Android docs describe the run-as
option:
Run commands on a device as an app (specified using the package name). This lets you run commands in
adb
as if the app you specify is running the command (that is, you have the same device access that the app has), without requiring root access. This might be necessary when usingadb
on a non-rooted device or an emulator with a Play store image. The app must be debuggable.
Related commands
I don’t have time to add much more to this right now, but one thing I’ll note is that if you have to run an ADB command where the file path has spaces in it, this command worked:
> adb shell run-as com.alvinalexander.mybrowser ls /data/data/com.alvinalexander.mybrowser/app_webview/Web\\ Data