skip to Main Content

I am trying to access the ‘Device Explorer’ tab in Android Studio for virtual device "Pixel 2 API 19". Unfortunately, it shows a red message saying Unable to access root directory of device: sh: stat: not found which does not tell me anything.

enter image description here

I have tried the following, but none has worked:

  • restarting the emulator;
  • restarting the device;
  • wiping data from the device;
  • closing the project and opening it again;
  • restarting my PC.

The problem seems to have appeared in the new version of Android Studio because it never used to be there before the update. My current version is Android Studio Hedgehog | 2023.1.1 Patch 1, my OS is Linux Mint XFCE.

I have also got virtual devices "Galaxy Nexus API 26" and "Pixel 2 API 23", but the error does not show for either of them.

2

Answers


  1. Have you tried running Android Studio as administrator? Some people have reported it fixing similar issues like this

    Login or Signup to reply.
  2. I encountered the same issue on my custom Oreo(27) build. Running android studio as admin did not work since the ‘Unknown command stat’ error was coming from device not the PC. And adb was already running as root.

    But curiously enough, I did not see the issue on an Oreo emulator. This lead me to believe the toybox in my custom build was missing stat for some reason.

    Android Studio uses ‘stat’ command to display the device contents under ‘Device Explorer’.

    On older android studio release (chipmunk), as per ddmlib logs, the request was rejected by adb (hence, why i didn’t see the issue earlier).

    .cache/Google/AndroidStudio2021.2/log/idea.log
    2024-01-08 13:20:45,058 [4233532]   WARN -            #com.android.ddmlib - ADB rejected shell command (stat -c %u /proc/3756 | xargs -n 1 cmd package list packages --uid): closed 
    

    For my custom Oreo device, I could see that this request fails due to ‘Unknown command stat’

    .cache/Google/AndroidStudio2023.1/log/idea.log
    2024-01-25 12:53:14,946 [  45542]   INFO - #com.android.tools.idea.adb.AdbShellCommandsUtil - Command took 140.4 ms to execute: su 0 sh -c 'stat -c "%A %U %G %z %s %n" /'
    2024-01-25 12:53:14,947 [  45543]   INFO - #com.android.tools.idea.adb.AdbShellCommandsUtil -   Output line 1 (out of 1): toybox: Unknown command stat
    

    Someone had accidentally removed stat from the toybox rules 6 years ago! I fixed it by regenerating toybox tools for my build.

    Not sure why this would be observed on an emulator. But I would say the android studio logs would be a good place to start.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search