Unable to open UIAutomatorviewer on Mac High Sierra

12,403

Solution 1

  • Installed older java(8) JDK
  • Updated Java version to 1.8 in JAVA_HOME

Commands used to update Java Version:

cd ~/
vim ~/.bash_profile
Updated the JAVA_HOME
Save in vim using :wq!
source ~/.bash_profile

enter image description here

  • Restart & UiAutomatorViewer is working! enter image description here

Solution 2

If you really don't want to upgrade to Java 11.0 but still want to run then this may help.

uiautomatorviewer works fine with Java version 8. You need not downgrade java version to 1.8. Instead add this method to .bash_profile

uiautomator() {
        export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home
        export ANDROID_HOME=/Users/<username>/Library/Android/sdk
        export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools:$ANDROID_HOME/tools
        /Users/<username>/Library/Android/sdk/tools/bin/uiautomatorviewer
}

This would set the JAVA_HOME path to 1.8 and includes android platform and build tools to path variable.

Either,

  1. Restart your terminal to get the changes reflected or
  2. Compile your .bash_profile by . .bash_profile in the current terminal to get it reflected.

Start typing uiautomator in your terminal. It should work !

Solution 3

You need Java 8 for uiautomator as mentioned in this as well as other threads. But you can do this without updating the JAVA_HOME variable.

Update the java_exe path in the uiautomator.bat file using any editor.

For Windows systems, find the line

set java_exe=call ..\lib\find_java.bat

Update that to:

set java_exe=C:\Program Files\Java\jdk1.8.0_271\bin\java.exe

In this way, you don't need to update the JAVA_HOME variable which has a higher jdk version(useful for other programs).

Share:
12,403
user2451016
Author by

user2451016

SDET and Frontend web developer.

Updated on June 18, 2022

Comments

  • user2451016
    user2451016 almost 2 years

    We have brand new MacBooks with High Sierra (10.13.6). Other system info:

    JAVA Version: java version "11.0.1" 2018-10-16 LTS
    

    Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)

    JAVA_HOME: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home

    When tried to open Android UIAutomatorViwer we're getting following error:

    /Library/Android/sdk/tools/bin/uiautomatorviewer ; exit;
    

    /Library/Android/sdk/tools/lib is not supported. Use -classpath instead. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. logout Saving session... ...copying shared history... ...saving history...truncating history files... ...completed. Deleting expired sessions...111 completed.

    More details: Java is at: /usr/bin/java

    enter image description here