【发布时间】:2020-10-25 08:28:34
【问题描述】:
我正在尝试使用 uiautomatorviewer 来捕获我通过 USB 连接的 Android 设备。 我已卸载 Android SDK 并重新安装。我对安装或连接等 adb 命令没有任何问题。如下所示,我可以看到带有 adb devices 命令的设备,并且在使用 adb version 命令时可以看到 adb 版本。问题是当我启动 uiautomatorviewer 我遇到 无法检测 adb 版本,adb 输出: 此时没有其他任何反应,程序也没有连接到我的设备。
PS C:\Windows\system32> adb devices
List of devices attached
a2738481 device
PS C:\Windows\system32> adb version
Android Debug Bridge version 1.0.41
Version 30.0.3-6597393
Installed as C:\android-sdk\platform-tools\adb.exe
PS C:\Windows\system32> uiautomatorviewer
03:55:06 E/adb: Unable to detect adb version, adb output:
Terminate batch job (Y/N)? y
PS C:\Windows\system32>
认为我的 uiautomatorviewer.bat 文件可能有问题
@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
for /f %%a in ("%APP_HOME%\lib\uiautomatorviewer-26.0.0-dev.jar") do set jarfile=%%~nxa
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 ('%frameworkdir%\..\bin\archquery') 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=C:\android-sdk\tools" -jar %jarpath% %*
请注意,当我在 C:\android-sdk\tools 中运行 monitor.bat 时,它可以正常工作
【问题讨论】:
标签: android automation adb android-sdk-tools