In UI automator viewer Error Obtaining Device screenshot, Reason : Error Unable to connect to adb. Check if adb is installed correctly

Open with text editor (notepad/vim) the uiautomatorviewer.bat.

Find that line:

call "%java_exe%" "-Djava.ext.dirs=%javaextdirs%" "-Dcom.android.uiautomator.bindir=%prog_dir%" -jar %jarpath% %*

and change it to call "%java_exe%" "-Djava.ext.dirs=%javaextdirs%" "-Dcom.android.uiautomator.bindir=C:\DEV\androidSDK\tools" -jar %jarpath% %*

Please notice that you should put your Tools' path after the bindir.


Another fix is to just copy adb.exe next to the uiautomatorviewer.bat.

If I remember correctly, modified files can confuse Android Studio when updating SDK, so you have to manually delete in order to successfully update, meaning more future proof solution. Example: link


In my case the problem was that the uiautomatorviewer location was user/library/android/sdk/tools/bin and I was using it via $ uiautomatorviewer. The app was working correctly, but when I tried to get the view hierarchy adb error occured. Solution? Open it via $ open uiautomatorviewer xD