错误分析
- 双击
uiautomatorviewer.bat
闪退 - 拖到
CMD
中运行报错如下,
修改uiautomatorviewer
- 右击该程序,点击
编辑
文本内容:
@echo off
rem Copyright (C) 2012 The Android Open Source Project
rem
rem Licensed under the Apache License, Version 2.0 (the "License");
rem you may not use this file except in compliance with the License.
rem You may obtain a copy of the License at
rem
rem http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.
rem don't modify the caller's environment
setlocal
rem Set up prog to be the path of this script, including following symlinks,
rem and set up progdir to be the fully-qualified pathname of its directory.
set prog=%~f0
rem Change current directory and drive to where the script is, to avoid
rem issues with directories containing whitespaces.
cd /d %~dp0
rem Get the CWD as a full path with short names only (without spaces)
for %%i in ("%cd%") do set prog_dir=%%~fsi
rem Check we have a valid Java.exe in the path.
set java_exe=
call lib\find_java.bat
if not defined java_exe goto :EOF
set jarfile=uiautomatorviewer.jar
set frameworkdir=.
if exist %frameworkdir%\%jarfile% goto JarFileOk
set frameworkdir=lib
if exist %frameworkdir%\%jarfile% goto JarFileOk
set frameworkdir=..\framework
:JarFileOk
set jarpath=%frameworkdir%\%jarfile%
if not defined ANDROID_SWT goto QueryArch
set swt_path=%ANDROID_SWT%
goto SwtDone
:QueryArch
for /f "delims=" %%a in ('"%java_exe%" -jar %frameworkdir%\archquery.jar') do set swt_path=%frameworkdir%\%%a
:SwtDone
if exist "%swt_path%" goto SetPath
echo SWT folder '%swt_path%' does not exist.
echo Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
exit /B
:SetPath
set javaextdirs=%swt_path%;%frameworkdir%
call "%java_exe%" "--Djava.ext.dirs=%javaextdirs%" "-Dcom.android.uiautomator.bindir=%prog_dir%" -jar %jarpath% %*
首先修改最后一行-Djava.ext.dirs
为--class-path
保存,重新打开CMD
,该问题解决
新问题初始化主类
此时产生了新的错误:无法初始化主类
在报错中,给出了原因:程序中没有使用swt lib库,被eclipse引用了
更换为你的此类似目录:D:\Java\android-sdk-windows\tools\lib\x86_64
即可
JDK更换版本
目前本机装配JDK版本为15.0.0,降低一个版本java版本1.8.0_281
,javac版本为11.0.10
- 下载官网
- 更换
JAVA_HOME
的值即可;其他变量如果不能正常启用,打开PATH
变量,双击对应变量值,确定
即可
- 问题解决