Appium appium 使用 UIAutomator 查找提示 java.lang.NoClassDefFoundError: com.android.uiautomator.core.Configurator

学飞 · December 10, 2014 · Last by 学飞 replied at December 11, 2014 · 1238 hits

求助,我在 appium 使用 UIAutomator 进行定位时提示 java.lang.NoClassDefFoundError: com.android.uiautomator.core.Configurator 的错误,报错代码如下:

WebElement element = driver.findElementByAndroidUIAutomator("new UiSelector().clickable(true).className(\"android.widget.RelativeLayout\")");
element.click();

但是直接是用 UIAutomator 来进行查找是可以的,如下

UiObject dm = new UiObject(new UiSelector().clickable(true).className("android.widget.RelativeLayout"));
dm.clickAndWaitForNewWindow();

附错误日志(部分):

> info: --> POST /wd/hub/session/5dbadf02-4f61-4d4e-af75-696d2453357c/element {"using":"-android uiautomator","value":"new UiSelector().clickable(true).className(\"android.widget.RelativeLayout\")"}
> info: [debug] Waiting up to 0ms for condition
> info: [debug] Pushing command to appium work queue: ["find",{"strategy":"-android uiautomator","selector":"new UiSelector().clickable(true).className(\"android.widget.RelativeLayout\")","context":"","multiple":false}]
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"-android uiautomator","selector":"new UiSelector().clickable(true).className(\"android.widget.RelativeLayout\")","context":"","multiple":false}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: find
> info: [debug] [BOOTSTRAP] [debug] Finding new UiSelector().clickable(true).className("android.widget.RelativeLayout") using ANDROID_UIAUTOMATOR with the contextId:  multiple: false
> info: [debug] [BOOTSTRAP] [debug] Parsing selector: new UiSelector().clickable(true).className("android.widget.RelativeLayout")
> info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: boolean arg: true
> info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: java.lang.Class<T> arg: "android.widget.RelativeLayout"
> info: [debug] [BOOTSTRAP] [debug] UiSelector coerce type: class java.lang.String arg: "android.widget.RelativeLayout"
> info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[CLASS=android.widget.RelativeLayout, CLICKABLE=true]
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] Error in testRunServer:
> info: [debug] [UIAUTOMATOR STDOUT] java.lang.NoClassDefFoundError: com.android.uiautomator.core.Configurator
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidElement.<init>(AndroidElement.java:26)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidElementsHash.addElement(AndroidElementsHash.java:47)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidElementsHash.getElement(AndroidElementsHash.java:89)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.handler.Find.fetchElement(Find.java:150)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.handler.Find.execute(Find.java:90)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidCommandExecutor.execute(AndroidCommandExecutor.java:64)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.SocketServer.runCommand(SocketServer.java:168)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.SocketServer.handleClientData(SocketServer.java:89)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.SocketServer.listenForever(SocketServer.java:133)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.Bootstrap.testRunServer(Bootstrap.java:16)
> info: [debug] [UIAUTOMATOR STDOUT] at java.lang.reflect.Method.invokeNative(Native Method)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:144)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:87)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:90)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
> info: [debug] [UIAUTOMATOR STDOUT] at dalvik.system.NativeStart.main(Native Method)
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stack=java.lang.NoClassDefFoundError: com.android.uiautomator.core.Configurator
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidElement.<init>(AndroidElement.java:26)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidElementsHash.addElement(AndroidElementsHash.java:47)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidElementsHash.getElement(AndroidElementsHash.java:89)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.handler.Find.fetchElement(Find.java:150)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.handler.Find.execute(Find.java:90)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidCommandExecutor.execute(AndroidCommandExecutor.java:64)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.SocketServer.runCommand(SocketServer.java:168)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.SocketServer.handleClientData(SocketServer.java:89)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.SocketServer.listenForever(SocketServer.java:133)
> info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.Bootstrap.testRunServer(Bootstrap.java:16)
> info: [debug] [UIAUTOMATOR STDOUT] at java.lang.reflect.Method.invokeNative(Native Method)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:144)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:87)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:90)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
> info: [debug] [UIAUTOMATOR STDOUT] at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
> info: [debug] [UIAUTOMATOR STDOUT] at dalvik.system.NativeStart.main(Native Method)
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.E
> info: [debug] [UIAUTOMATOR STDOUT] Time: 13.086
> info: [debug] [UIAUTOMATOR STDOUT] FAILURES!!!
> info: [debug] [UIAUTOMATOR STDOUT] Tests run: 1,  Failures: 0,  Errors: 1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
> info: [debug] UiAutomator exited
共收到 16 条回复 时间 点赞

你的设备是神马版本?

#1 楼 @lihuazhang 好吧,是 4.2.2,刚试了下 5.0 的就可以了~~~~ 为啥 4.2.2 的直接用 UIAutomator 就可以,用 appium 就不行了呢

#2 楼 @felix 4.2.2 是 api17,应该可以用。 你在看看是不是 4.1.2

#3 楼 @lihuazhang 是 17 的,看了 build.prop 的信息,而且直接使用 UIAutomator 也是可以运行的

ro.build.version.sdk=17
ro.build.version.codename=REL
ro.build.version.release=4.2.2

Android SDK Platform, API 16 or higher

#5 楼 @lihuazhang 符合这个条件~~ 刚发现

driver.swipe(200, 200, 0, 200, 1000);

这个方法在 api17 上运行也是有问题的 放到 21 上运行正常

#6 楼 @felix 有一些特性的确不是很一致。。。

请问 楼主这个问题解决了没?

想请教下怎么解决的,我用的是 Python 来写的脚本,脚本运行时报的错:
selenium.common.exceptions.WebDriverException: Message: 'UiAutomator died while responding to command, please check appium logs!'

appium 日志报错:

info: [debug] [UIAUTOMATOR STDOUT] Error in testRunServer:
info: [debug] [UIAUTOMATOR STDOUT] java.lang.NoClassDefFoundError: com.android.uiautomator.core.Configurator
info: [debug] [UIAUTOMATOR STDOUT] at io.appium.android.bootstrap.AndroidElement.(AndroidElement.java:26)
......

请问楼主也是遇到这种问题么? 希望赐教一下,感激不尽

#8 楼 @ww32245420 对于 api17 这个特殊的版本, appium 支持的不积极. 好像它只允许 api17 以上的, 如果是 api17 也会提示不支持. 最好使用以上的版本.

#9 楼 @seveniruby

我如果选择其他版本 比如 API18 19 就会报:
selenium.common.exceptions.WebDriverException: Message: 'UiAutomator died while responding to command, please check appium logs!'

不知道为啥

#10 楼 @ww32245420 uiautomator 的确是启动超时了, 得排查下原因

lz,我也遇到了同样的问题,请问 lz 解决了吗? 感觉这是 appium 的 bug 啊。。。

#11 楼 @seveniruby
但是 我单独启动的时候 还是可以正常打开 uiautomator 呢
不知道如何下手排查 郁闷...

#13 楼 @ww32245420

info: [debug] [UIAUTOMATOR STDOUT] Error in testRunServer:
info: [debug] [UIAUTOMATOR STDOUT] java.lang.NoClassDefFoundError: com.android.uiautomator.core.Configurator

我今天也遇到同样的问题。查了下,android4.2.2 下的 uiautomator 源码里面确实没有 Configurator 类的定义,至少要在 4.3 版本上才有,所以基本可以断定,要想成功运行,至少必须在 4.3 或以上的版本才行。

#15 楼 @qinggchu

确实,我在 4.3 和 4.4 上都成功运行了...........4.2 无论哪种方式都不行 放弃了

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up