作为日常工作,常常要使用Android SDK附带的hierarchyviewer、uiautomatorviewer、ddms等工具,刚好碰上Android L发布,并且更新了Android Stutio 1.0,SDK也伴随着进行了大幅度更新,包括uiautomatorviewer等在内的工具都有了新版本。于是昨天下了新版本过来,安装上去,接着重新设置了环境变量等一系列东西,然后打开uiautomatorviewer,竟然提示出错:
‘-v’ 不是内部或外部命令,也不是可运行的程序
或批处理文件。
无效路径
ERROR: SWT folder ” does not exist.
Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
莫非是我环境配置有问题?Google了一下,发现大部分答案都是让设置ANDROID_SWT的环境变量,或者吧jdk移动到PATH的第一个云云的奇怪办法,所以试了半天放弃了,还是安心调试调试看看咋回事。
把uiautomatorviewer.bat的第一行@echo off加冒号”:”注释掉,然后运新一下,看输出:
C:Usersxxx.xxx>rem Copyright (C) 2012 The Android Open Source Project ...... C:Usersxxx.xxxAppDataLocalAndroidsdktools>rem Check we have a valid Java.exe in the path. C:Usersxxx.xxxAppDataLocalAndroidsdktools>set java_exe= C:Usersxxx.xxxAppDataLocalAndroidsdktools>call libfind_java.bat SWT folder '' does not exist. Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
C:Usersxxx.xxx>rem Copyright (C) 2012 The Android Open Source Project
......
C:Usersxxx.xxxAppDataLocalAndroidsdktools>rem Check we have a valid Java.exe in the path.
C:Usersxxx.xxxAppDataLocalAndroidsdktools>set java_exe=
C:Usersxxx.xxxAppDataLocalAndroidsdktools>call libfind_java.bat
SWT folder '' does not exist.
Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
运行到call libfind_java.bat这一行出问题鸟~~
接着摸出来find_java.bat,注释掉第一行的 @echo off,看输出:
...... for /F "delims=" %a in ('"C:Usersxxx.xxxAppDataLocalAndroidsdktoolslibfind_java32 .exe" -s') do set java_exe=%a ......
......
for /F "delims=" %a in ('"C:Usersxxx.xxxAppDataLocalAndroidsdktoolslibfind_java32 .exe" -s') do set java_exe=%a
......
find_java32 .exe是什么鬼……
打开find_java.bat的代码,可以看到27行这里
for /f "delims=" %%a in ('"%~dps0find_java%arch_ext%.exe" -s -w') do set javaw_exe=%%a
for /f "delims=" %%a in ('"%~dps0find_java%arch_ext%.exe" -s -w') do set javaw_exe=%%a
就是本尊了,往上翻到arch_ext:
find /i "x86" > NUL && set arch_ext=32 || set arch_ext=64
find /i "x86" > NUL && set arch_ext=32 || set arch_ext=64
那个空格应该是这里了,可能是工程师们java写多了,bat里手也瓢了,把前后的空格去掉试试~~
find /i "x86" > NUL && set arch_ext=32||set arch_ext=64
find /i "x86" > NUL && set arch_ext=32||set arch_ext=64
关掉cmd,重新打开,新版的uiautomatorviewer出现鸟~~接着测试一下其他需要用到call libfind_java.bat的工具(tools里的几乎都要用吧),都没问题了。