On Android Studio, click on Menu Tools > SDK Manager
Go to SDK tools tab, uncheck option "Hide Obsolete Packages"
Check option “Android SDK Tools” and install version 26.1.1
UIautomatorviewer is now installer in the SDK directory : $ANDROID_HOME/tools/bin
The default path for the SDK depends of the OS :
For windows : ANDROID_HOME = c:\USERS\USER\AppData\Local\Android\Sdk (replace USER by your user profile)
For linux : ANDROID_HOME = $home\Android\Sdk
To use uiautomatorviewer, open a terminal and go to the path in the SDK android :
For windows
Code Block |
---|
cd %ANDROID_HOME%\tools\bin
uiautomatorviewer.bat |
For linux
Code Block |
---|
cd $ANDROID_HOME/tools/bin
./uiautomatorviewer |
if ANDROID_HOME variable is not set, referer to the table below.
If you have en error and uiautomatorviewer does not open, this is probably because uiautomatorviewer is configured to use by default java JDK version 1.8
To avoid installing a different version of java, you could :
set environment variables for your PC profile
...
Default path for windows
...
Default path for Linux
...
ANDROID_HOME
...
add this variable to precise the path on the sdk android
...
c:\Users\USER\AppData\Local\Android\Sdk
...
$home\android\sdk
...
JAVA_HOME
...
add this variable to set the path to the JDK. you can use the jdk installed by android studio
...
c:\Program Files\Android\Android Studio\jbr
if jbr is not present (old version Android Studio, replace by jre)
...
$home\android-studio\jbr
if jbr is not present (old version Android Studio, replace by jre)
...
PATH
...
Complete the path by adding the path to directory containing the java executable.
Do not replace PATH value, only add new entry
...
%JAVA_HOME%\bin
...
$JAVA_HOME\bin
...
After adding the variables, you can open a new terminal (this is important to open a new terminal to take into account the variable you have just set) and use the following command to open uiautomatorviewer :
For windows :
Code Block |
---|
java -Xmx1600M -Dcom.android.uiautomator.bindir="%ANDROID_HOME%\tools" -cp "%ANDROID_HOME%\tools\lib\x86_64\swt.jar":"%ANDROID_HOME%\tools\lib\*" com.android.uiautomator.UiAutomatorViewer |
For linux :
Code Block |
---|
java -Xmx1600M -Dcom.android.uiautomator.bindir="$ANDROID_HOME/tools" -cp "$ANDROID_HOME/tools/lib/x86_64/swt.jar":"$ANDROID_HOME/tools/lib/*" com.android.uiautomator.UiAutomatorViewer |
...
Note |
---|
UIAutomator a besoin de la version 8 de Java par défaut pour fonctionner. |
...
The installation of uiautomatorviewer is described here How to get element of a view (id, text, class, description) to write GDSL test (Android)