最近升级了AndroidSDK,打开UIAutomatorViewer.bat,结果发现获取不了Android设备界面上的UI信息。经过一番努力,终于把这个问题解决了,详细过程如下:

1. Unable to connect to adb.Check if adb is installed correctly.问题:

UIAutomatorViewer.bat位于AndroidSDK\tools\bin路径下,是个十分常用的自动化测试工具,双击运行即可。谁知更新了最新的AndroidSDK之后,运行UIAutomatorViewer.bat就出现了以下错误:

Unable to connect to adb.Check if adb is installed correctly.

2. 解决方案

打开uiautomatorviewer.bat,将最后一句%prog_dir%替换成AndroidSDK\tools路径,保存后再次打开uiautomatorviewer.bat即可得到当前View所有信息。

uiautomatorviewer.bat源码片段

替换上一句为下面这句:

uiautomatorviewer.bat源码片段修改后

3. 为什么这么修改就能解决问题了呢?

1) 打开uiautomatorviewer.bat,发现最后一句是关键代码,也许问题就出现在这里。

2) 打印出这最后一句里4个变量,可以得到如图所示路径,除了prog_dir,其他3个很显然都没有问题。

3) 反编译uiautomatorviewer-25.3.2.jar,搜索com.android.uiautomator.bindir,在以下文件中找到相应的代码,

由此可见jar文件里:

A. prog_dir就是这里的toolsDir;

B. Sdk路径是prog_di的父路径;

C. adb路径是prog_di的父路径下platform-tools文件夹。

uiautomatorviewer源代码片段

再看uiautomatorviewer.bat,prog_dir= D:\android\AndroidSDK\tools\bin,因此

A. toolsDir路径就是D:\android\AndroidSDK\tools\bin;

B. Sdk路径是D:\android\AndroidSDK\tools\;

C. adb路径是D:\android\AndroidSDK\tools\platform-tools,显然这个路径并不存在,于是就出现了unable to connect adb。

所以将com.android.uiautomator.bindir设置成AndroidSDK\tools路径,问题就解决了。

UIAutomatorViewer 出现错误:Unable to connect to adb的更多相关文章

  1. uiautomatorviewer提示Unable to connect to adb. Check if adb is installed correctly解决方法

    转自:https://www.jianshu.com/p/c8581a70d1bc 解决方案: 1.打开  "E:\android-sdk_r24.4.1-windows\android-s ...

  2. 错误 Unable to connect to a repository at URL 'svn://ip地址' 和 No repository found in 'svn://ip地址'

    SVN服务器是CentOS6.10 使用TortoiseSVN客户端检出时遇到如下图所示的错误: 是因为没有指定SVN仓库的路径 在SVN服务器执行命令:svnserve -d -r /SVN版本库的 ...

  3. telnet报“Unable to connect to remote host:Connection refused”错误

    Linux下面telnet ip 端口号 报错误"Unable to connect to remote host:Connection refused"的时候,大部分是目标机的端 ...

  4. [automator篇][5]Viewer 提示connect to adb fail

    7. UIAutomatorViewer提示: Unable to connect to adb. Check if adb is installed correctly 解决,sdk升级到了25产生 ...

  5. svn检出的时候报 Unable to connect to a repository at URL错误(摘自CSDN)

    背景:1.         SVN服务器:VisualSVN-Server-2.5.5: 2. SVN客户端:TortoiseSVN-1.7.6.22632-x64-svn-1.7.4.msi: 在S ...

  6. svn 提交错误 400 Bad Reqest MKACTIVITY 请求于XX失败 Conflict Unable to connect to a repository at URL

    思路来源:http://www.cnblogs.com/wangyt223/archive/2012/11/22/2782801.html svn 提交错误 400 Bad Reqest MKACTI ...

  7. selenium 运行之后错误提示Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output

    错误提示: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port ...

  8. unable to connect to ssl://gateway.sandbox.push.apple.com:2195 错误

    使用APNS 搭建苹果推送服务器错误:unable to connect to ssl://gateway.sandbox.push.apple.com:2195 错误 1:检查你的服务器的端口 21 ...

  9. 如何用Adb连接Android手机 & unable to connect to 192.168.1.100:5555的原因和解决方法

    利用adb来连接手机, 有两种方式: 1, wifi 2, usb. 1. 通过wifi, 利用adb来连接手机. 在pc的cmd中输入命令: adb connect 192.168.1.100 其中 ...

随机推荐

  1. Jenkins2.32用户和权限管理策略

    前言 在使用jenkins的过程中,需要为不同的角色分配相应的权限,如果jenkins的用户数据能和公司现在的帐号系统结合起来那会更好. 关于如何为用户分组,我推荐使用 role based auth ...

  2. Java的基础知识二

    一.方法函数 函数也称为方法,就是定义在类中的具有特定功能的一段独立代码.用于定义功能,提高代码的复用性. 函数的特点1> 定义函数可以将功能代码进行封装,便于对该功能进行复用:2> 函数 ...

  3. LeetCode算法题-Power of Four(Java实现-六种解法)

    这是悦乐书的第205次更新,第216篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第72题(顺位题号是342).给定一个整数(带符号的32位),写一个函数来检查它是否为4 ...

  4. 新近碰到的病毒(TR.Spy.Babonock.A)

    先来段Microsoft的说明: Worm:Win32/Babonock.A Alert level: Severe Detected with Windows Defender Antivirus ...

  5. python 守护进程、同步锁、信号量、事件、进程通信Queue

    一.守护进程 1.主进程创建守护进程 其一:守护进程会在主进程代码执行结束后就终止 其二:守护进程内无法再开启子进程,否则抛出异常:AssertionError: daemonic processes ...

  6. nginx: worker process is shutting down

    正常情况下,nginx进程状态如下: 当修改配置文件,reload之后: PID=17114的wroker有正在处理的连接,等处理结束,该worker就会退出(退出之前,该worker不会处理新的连接 ...

  7. C#定时备份正在播放的幻灯片、word文档、excel电子表格,mht格式文档

    控制台应用, 代码如下: using System; using System.Collections.Generic; using System.IO; using System.Linq; usi ...

  8. 在Ubuntu18.04上使用Anaconda(python3.7)环境中安装tensorflow1.13.1

    由于清华镜像源迟迟没有更新tensorflow1.13.1导致python3.7不能使用tensorflow 这里有一个解决方法 管理员模式打开(一定要管理员模式 不然会导致权限不足) 输入 pip ...

  9. MYSQL动态查询拼接的表名的SQL脚本实现(MYSQL动态执行SQL脚本)

    可以使用MYSQL的预处理逻辑:https://dev.mysql.com/doc/refman/8.0/en/sql-syntax-prepared-statements.html   例如: pr ...

  10. selenium之选项卡管理

    在使用selenium管理浏览器的时候遇到一些小问题,现将这些小问题作一下总结: (1)browser是什么? from selenium import webdriver browser = web ...