打开uiautomatorviewer 时在终端中报错
bloguan@bloguandeMacBook-Pro ~ % /Users/bloguan/Library/Android/sdk/tools/bin/uiautomatorviewer ; exit;
-Djava.ext.dirs=/Users/bloguan/Library/Android/sdk/tools/lib/x86_64:/Users/bloguan/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.
解决方法:更换JDK版本
执行命令 java -version
java version "14.0.1" 2020-04-14
Java(TM) SE Runtime Environment (build 14.0.1+7)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
当前系统jdk版本是14
先下载安装JDK8 https://www.oracle.com/java/technologies/downloads/#java8
安装
接下来就是切换JDK版本
终端中输入
open ~/.bash_profile
打开文件,添加以下内容
export JAVA_14_HOME=/Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home
export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
export JAVA_HOME=$JAVA_14_HOME
export PATH=$JAVA_HOME/bin:$PATH
保存退出,执行刷新命令
source ~/.bash_profile
再java -version 得到
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
再打开uiautomatorviewer,启动成功!
扩展:
home目录下的.bash_profile 有人可能没有,如果没有就新建一个,另外还需要在同级目录下 .zshrc文件中添加以下内容,保证启动时会生效
source ~/.bash_profile
发表评论