Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uiautomatorviewer - Error: Could not create the Java Virtual Machine

I am trying to run uiautomatorviewer in terminal. I am getting this error:

-Djava.ext.dirs=/Users/<Username>/Library/Android/sdk/tools/lib/x86_64:/Users/<Username>/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. 

I think this might be related to the java version I am using. Here is the output of java -version:

java version "10" 2018-03-20 Java(TM) SE Runtime Environment 18.3 (build 10+46) Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode) 

I have already seen this question on SO, but it recommends downgrading to java 8.

Am I missing anything here? I would appreciate any help.

like image 427
Praveen Singh Avatar asked Mar 27 '18 06:03

Praveen Singh


People also ask

How do I start Uiautomatorviewer?

If you have set up the Android SDK path, open the Terminal (Command Prompt in Windows) and type in the uiautomatorviewer command. This will launch a blank window with a couple of icons on top, as illustrated in the following screenshot.

Is Uiautomatorviewer deprecated?

Unfortunately, we have got the information that UiAutomator 1.0 was deprecated. This version of UI Automator is deprecated. New tests should be written using UI Automator 2.0 which is available as part of the Android Testing Support Library.


1 Answers

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 !

like image 92
Tom Taylor Avatar answered Sep 16 '22 15:09

Tom Taylor