I am making this question for future searchers that might be as newbie as me. And also because I have not enough reputation to add comments on other answers.
The error mentioned still happened after trying the following approaches:
- Turn on USB DEBUGGING
- Enable view attribute inspection
- Select the debug app option and choose com.github.uiautomator
Error in using UIAutomatorviewer for testing Android app in Appium
The problem was that the whereis uiautomatorviewer throwed this path /usr/bin/uiautomatorviewer
Solution
The one that actually does the work is /root/Android/Sdk/tools/bin/uiautomatorviewer