Search code examples
androidemulationrootsuandroid-studio-2.3

How can I get root access on an Android 7.0 emulator?


I'm developing an android application which writes some json files into the external storage. For development I want to have a look for the written json files.

I know that I can view these files with root access in /data/data/package-name/.

But how can I get root access on the Android 7.0 Emulator?

I already tried the su command in the adb shell and also adb root - but then I get this error message: adbd cannot run as root in production builds

Maybe you have some advice?


Solution

  • I'm writing the json files to /data/data//files using context.getFilesDir().getPath() + "/" + fileName

    That is internal storage, not external storage.

    Use adb shell run-as ... ??? to run commands as your app's user, which will allow those commands to access internal storage. Here, ... is the application ID of your app, and ??? is a command.

    So, for example, to list the contents of a typical location for getFilesDir() for an app whose user ID is com.foo.bar, use:

    adb shell run-as com.foo.bar ls /data/data/com.foo.bar/files
    

    This only works for debuggable apps.