无法创建Java虚拟机

无法创建Java虚拟机

本文介绍了uiautomatorviewer-错误:无法创建Java虚拟机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在终端中运行uiautomatorviewer.我收到此错误:

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.

我认为这可能与我使用的Java版本有关.这是java -version的输出:

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)

我已经看到关于SO的这个问题,但是它建议降级到Java 8.

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.

推荐答案

uiautomatorviewer在Java版本8上运行良好.您无需将Java版本降级到1.8.而是将此方法添加到.bash_profile

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
}

这会将JAVA_HOME路径设置为1.8,并包括android平台和用于构建路径变量的构建工具.

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

要么

  1. 重新启动终端以反映更改或
  2. 在当前终端中用. .bash_profile编译您的.bash_profile以使其得到反映.
  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.

开始在终端中键入uiautomator.它应该可以工作!

Start typing uiautomator in your terminal. It should work !

这篇关于uiautomatorviewer-错误:无法创建Java虚拟机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 02:53