Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

Uiautomatorviewer failed to start

I observed other people’s UI codes and found that the PREVIOUSLY configured UIAutomator could not be used, so I tried to solve it. Uiautomator is used for UI testing. On Android, each component is a NodeInfo. Uiautomator provides detailed component properties that can be referred to in some cases to determine if the UI is as expected.

The uiAutomatorViewer path is in the Tools /bin directory of the Android SDK.

Windows client to solve

Unable to open UIAutomatorViewer in Windows, an incorrect popup window will appear.

Uiautomatorviewer is dependent on the Java environment, if the JDK version is higher than Java8, it will not start, probably because Google has not adapted it.

So how to solve it?

First, demote Java environment variables to Java8

The second way is to edit the code in UIAutomatorView.bat so that it enforces the java8 environment so that global environment variables do not need to be degraded.

Add the following code to uiAutomatorViewer.

Set the JAVA_HOME = C: / Java/java1.8 set java_exe = "% JAVA_HOME %"/bin/Java. ExeCopy the code

The Mac address

The Mac version of UIAutomatorViewer behaves differently from Windows. It cannot be opened on Windows, while on Mac, the button cannot be clicked after it is opened.

Later, I found that almost all SWT programs could not be used, my macOS version is BigSur, I struggled for a long time, but I did not find the problem, I guess it is because of the MAC version, I guess it is because there is no permission in the auxiliary function, but the permission is still not available.

The first way

Use a modified version from a third party.

Later, I found out that Google provided the official code library for these programs, and some great people would do secondary development based on these libraries. I visited Github, and many people made improvements on UIAutomator.

Then I found someone on Github doing secondary development on it. I tried to download it and it is available.

Github.com/cmlanche/ui…

How do you use it?

cd /Users/XXX/Desktop/Tools/uiautomator java -XstartOnFirstThread -jar / Users/XXX/Desktop/Tools/uiautomator/uiautomatorviewer - standalone - 1.1 - all the jarsCopy the code

The second way

Replace imperfect libraries.

This is a problem with Mac bigSur.

Sqa.stackexchange.com/questions/4…

The problem appears to be the same as the one you saw. Download the latest version of the Eclipse project, unzip it, rename swt.jar to swt2.jar, And then copied to the ~ / Library/Android/SDK/tools/lib/x86_64 / swt2 jar. This solution was originally proposed in this problem report. Some people say that they also have to copy it to the ~ / Library/Android/SDK/tools/lib/x86 / swt2. The jar, but I really need to do so. In my case, I downloaded the 4.19 Mac OSX (64-bit version) version for my (non-ARM) MacBook Pro. You can find additional versions on the Eclipse project download page.Copy the code

Download the SWT

Download.eclipse.org/eclipse/dow…

Note: keep the original SWT unchanged, rename the downloaded SWT to SWT2 and move it to the corresponding directory.