[Solved] uiautomatorviewer Error: Error obtaining UI hierarchy

1. Problem reappearance: when learning appium framework and using uiautomatorviewer to locate Android App controls, directly selecting [device screenshot] will report an error:

2. Solution:

Create a new bat file with the following contents:

adb shell uiautomator dump /sdcard/screen.uix
adb pull /sdcard/screen.uix D:/uiscreen/screen.uix
adb shell screencap -p /sdcard/screen.png
adb pull /sdcard/screen.png D:/uiscreen/screen.png

In fact, these commands can also be directly input in CMD, but they need to be input every time, which is more troublesome. All commands can be written into bat files and run directly to obtain interface information.

3. Select the path of the picture and uix file in uiautomatorviewer:

My frame is too small. I can’t click the path of the second uix at all. The solution is to press the tab key, locate the button to select the file, and then enter can select it normally.

4. Then you can load the interface and locate the elements normally.

Read More: