Trevor Wang
Trevor Wang

Reputation: 304

uiautomatorviewer not working on latest MacOS

I am trying to using uiautomatorviewer on MacOS 10.15. I got the below error.

enter image description here

I tested uiautomatorviewer on MacOS 10.13. it works pretty well.

Here's the error message:

Unexpected error while obtaining UI hierarchy java.lang.reflect.InvocationTargetException  on latest Mac OS

Here's the log detail

Unhandled event loop exception during blocked modal context.
org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NullPointerException)
    at org.eclipse.swt.SWT.error(Unknown Source)
    at org.eclipse.swt.SWT.error(Unknown Source)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Unknown Source)
    at org.eclipse.swt.widgets.Display.runAsyncMessages(Unknown Source)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
    at org.eclipse.jface.operation.ModalContext$ModalContextThread.block(ModalContext.java:173)
    at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:388)
    at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)
    at com.android.uiautomator.actions.ScreenshotAction.run(ScreenshotAction.java:85)
    at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
    at ialogs.ProgressMonitorDialog$ProgressMonitor.subTask(ProgressMonitorDialog.java:234)

Upvotes: 3

Views: 8280

Answers (2)

shofin
shofin

Reputation: 144

this problem happening for SDK version. I solved my problem by doing the followings -

Downgrade your Java version to "1.8.0_231" you can get here: https://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html

set the env in your bash_profile. to do that

go to MAC DISK and find ".bash_profile" Open,edit and set the path

example:

export ANDROID_HOME=~/Library/Android/sdk
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home

export PATH=$PATH:$JAVA_HOME/bin
export PATH=$PATH:$JAVA_HOME/lib
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/build-tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/tools/lib/x86_64

quit the terminal and reopen type "uiautomatorviewer" and hit enter...

thats it.

Upvotes: 4

Sierisimo
Sierisimo

Reputation: 648

TL;DR: What worked in my case was doing a downgrade of the Java version I was using.

To quickly do this I recommend installing sdkman and install a lower version of your current Java version.

In my case I was using the 8.0.262.hs-adpt (as listed in SDKman) and having troubles like no visible text/null pointer exceptions at terminal.

After downgrade to 8.0.252.hs-adpt, all error are gone and currently working.


Detailed steps:

  1. Install SDKman (one liner: curl -s "https://get.sdkman.io" | bash )
  2. Open a new tab/terminal
  3. Search SDKman for a JDK lower than 8.0.262: sdk list java (in my case the AdoptOpenJDK 8.0.252.hs-adpt)
  4. Install it with sdk install java <VERSION_YOU_CHOOSE>
  5. Launch uiautomatorviewer in the same terminal you installed the JDK.

You can also use sdk use java <VERSION> in case you already have another JDK installed or sdk default java <VERSION> in case you want you want to always point to an specific version.

Upvotes: 0

Related Questions