问题
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.
回答1:
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,
- Restart your terminal to get the changes reflected or
- Compile your
.bash_profile
by. .bash_profile
in the current terminal to get it reflected.
Start typing uiautomator
in your terminal. It should work !
回答2:
uiautomatorviewer is not compatible with java10 as far as I can tell. Switching to java8 fixed it for me.
回答3:
Following worked for me (Ubuntu 16.04, Java 11):
$ export YOUR_SDK_PATH="/home/user/Android/Sdk/"
$ java -Xmx1600M -Dcom.android.uiautomator.bindir="$YOUR_SDK_PATH/tools" -cp "$YOUR_SDK_PATH/tools/lib/x86_64/swt.jar":"$YOUR_SDK_PATH/tools/lib/*" com.android.uiautomator.UiAutomatorViewer
回答4:
I also faced the same issue and i did the following in my uiautomatorviewer file. Instead of this line:
exec "${javaCmd}" $javaOpts -Djava.ext.dirs="$frameworkdir" -Dcom.android.uiautomator.bindir="$progdir" -jar "$jarpath" "$@"
I replaced the same using Classpath and it worked:
exec java -Xmx1600M -XstartOnFirstThread -Dcom.android.uiautomator.bindir=/your-sdk-path/tools -cp /your-sdk-path/tools/lib/x86_64/swt.jar:/your-sdk-path/lib/uiautomatorviewer.jar:/your-sdk-path/tools/lib/.jar:. com.android.uiautomator.UiAutomatorViewer*
Replace your-sdk-path with the location of sdk on your system. You can try this command directly on your terminal also and it will launch 'UiAutomatorViewer' without doing any changes around java.
回答5:
Moving back Java 8 has fixed the problem for me. After you have installed Java 8, make sure your environment variables are not pointing to your previously installed Java.
来源:https://stackoverflow.com/questions/49506036/uiautomatorviewer-error-could-not-create-the-java-virtual-machine