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
cd %ANDROID_HOME%\tools\bin uiautomatorviewer.bat
For linux
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. | %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 :
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 :
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
UIAutomator a besoin de la version 8 de Java par défaut pour fonctionner.
Si vous avez une version de java > 8, et que vous avez une erreur dans la commande précédente, vous pouvez ouvrir un terminal de commande et taper la commande suivante qui fonctionnera dans n’importe quel dossier