最近在新版本 Android 10 下尝试使用常用的 uiautomatorviewer 定位元素,但不管怎么更新 SDK 都失败了,
大概就是下面这个样子
Reason:
Unexpected error while obtaining UI hierarchy
Details:
java.lang.reflect.InvocationTargetException
image
经历了一顿搜索,发现很多小伙伴在 Android 8 的时候就开始遇到了这个问题,很多帖子也给出了曲线救国方法,
像这样:
image
或者这样:
image
但还是没有解决我的问题
image
只能去 Google 官网找答案了
了解到 uiautomatorviewer 是 Android SDK Tools 下的工具, 理论上 Android 系统更新了,我们只需要使用 SDK Manager 更新下就好了,
于是我打开了 SDK Manager, 发现根本找不到 API Level 29 的 Android SDK Tools
image
API Level | 最初Android版本 | Linux内核版本 | 首次发布日期 |
---|---|---|---|
29 | 10 | Unknown | 2019-06-05(Beta 4) |
28 | 9 | 4.4.107, 4.9.84, and 4.14.42 | 2018-08-06 |
27 | 8.1 | 4.10 | 2017-12-05 |
26 | 8.0 | 4.10 | 2017-08-21 |
25 | 7.1 | 4.4.1 | 2016-10-04 |
最后在开发者官网下找到了说明:SDK 工具软件包在新版本中已经弃用了
image
如此一来希望就破灭了吗?
No No No!!! 继续 Google Baidu, 终于在 github 上找到一个改装的 uiautomatorview
github:https://github.com/yaming116/uiautomatorview
使用方法也较简单,主要涉及到两个 jar 包:
- cmd 中运行
adb push LvmamaXmlKit.jar /data/local/tmp/
- 将下载的
uiautomatorviewer.jar
,替换你本地的${ANDROID_HOME}/tools/lib
下的uiautomatorviewer.jar
为了方便大家国内下载,我也传了一份在 CSDN 中