8

I am trying to start uiautomatorviewer from default sdk installed location using terminal (Ubuntu 16) :

>abc@abc:~/Android/Sdk/tools/bin$ ./uiautomatorviewer

and I am getting an error as below :

Error

-Djava.ext.dirs=/home/mukesh/Android/Sdk/tools/lib/x86_64:
/home/abc/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.

Till yesterday things are working fine for me . So , far I tried looking into the post unable to start uiautomatorviewer

but what I am getting is a different error , Forgive me but I am a newbie to this and absolutely no idea of what went wrong in one day , Any help to resolve the error would be highly appreciated .

coder3521
  • 2,608
  • 1
  • 28
  • 50

2 Answers2

17

Finally I was able to find out a solution , so just posting the same for other's reference :

Downgrading the Java version from 9 to 8 resolved the issue :

Command Used :

sudo update-alternatives --config java

This is list out the version installed like this with * on the selected version :

     Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-9-openjdk-amd64/bin/java       1091      auto mode
* 1            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  2            /usr/lib/jvm/java-9-openjdk-amd64/bin/java       1091      manual mode

Press <enter> to keep the current choice[*], or type selection number: 

Enter here the number 1 as we need version 8 .

Thats's all done , rerun uiautomatorviewer .

EDIT:

If You see something like "you don't have any alternatives" try donwloading openjdk-8 from the link below (for linux)

Install open jdk-8

Rashad Nasirli
  • 457
  • 3
  • 16
coder3521
  • 2,608
  • 1
  • 28
  • 50
  • How to achieve this on Mac High sierra? – user2451016 Dec 14 '18 at 10:52
  • In my system, I have only one Version of Java, so I am getting this message, 'There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-11-openjdk-amd64/bin/java Nothing to configure.' – M.J Jul 23 '19 at 14:19
  • In case you need to install some Java version manually on a Ubuntu-based Linux distro this guide does the trick: https://www.digitalocean.com/community/tutorials/how-to-manually-install-oracle-java-on-a-debian-or-ubuntu-vps – Julian Borrero Oct 06 '19 at 01:32
4

for the record, uiautomatorviewer requires java8 and if your system doesn have it, then you need to install it.

for ubuntu, do the following as root,

apt-get install openjdk-8-jdk
update-alternatives --config java #choose java8
IslamTaha
  • 1,056
  • 1
  • 10
  • 17