Appium [请教] appium1.8.1 的版本在 capabilities 配置使用 uiautomator2 之后报创建 session 出错

Raykin · 2018年07月25日 · 最后由 回复于 2019年11月01日 · 4361 次阅读

我是小白,最近刚接触 appium,想使用 uiautomator2 捕获 toast 信息,但是发现使用 uiautomator2 会启动报错,把 “automationName: Uiautomator2” 配置项去掉,能正常启动。请教各位大神,希望能指点一下小弟,万分感激。

appium-desktop 版本是 1.6.2

启动日志信息:

The server is running
[Appium] Welcome to Appium v1.8.1
[Appium] Non-default server args:
[Appium] address: 127.0.0.1
[Appium] Appium REST http interface listener started on 127.0.0.1:4723
[HTTP] --> GET /wd/hub/sessions
[HTTP] {}
[MJSONWP] Calling AppiumDriver.getSessions() with args: []
[MJSONWP] Responding to client with driver.getSessions() result: []
[HTTP] <-- GET /wd/hub/sessions 200 21 ms - 40
[HTTP]
[HTTP] --> POST /wd/hub/session
[HTTP] {"desiredCapabilities":{"appActivity":".MainActivity","appPackage":"com.example.hrst.mycalcutor","appWaitActivity":"hrst.MainActivity","automationName":"Uiautomator2","deviceName":"JTJ4C15B02036806","noReset":true,"platformName":"Android","platformVersion":"5.1.1","newCommandTimeout":0,"connectHardwareKeyboard":true}}
[MJSONWP] Calling AppiumDriver.createSession() with args: [{"appActivity":".MainActivity","appPackage":"com.example.hrst.mycalcutor","appWaitActivity":"hrst.MainActivity","automationName":"Uiautomator2","deviceName":"JTJ4C15B02036806","noReset":true,"platformName":"Android","platformVersion":"5.1.1","newCommandTimeout":0,"connectHardwareKeyboard":true},null,null]
[BaseDriver] Event 'newSessionRequested' logged at 1532530294546 (22:51:34 GMT+0800 (中国标准时间))
[Appium] Creating new AndroidUiautomator2Driver (v1.12.0) session
[Appium] Capabilities:
[Appium] appActivity: .MainActivity
[Appium] appPackage: com.example.hrst.mycalcutor
[Appium] automationName: Uiautomator2
[Appium] deviceName: JTJ4C15B02036806
[Appium] noReset: true
[Appium] platformName: Android
[Appium] platformVersion: 5.1.1
[Appium] newCommandTimeout: 0
[Appium] connectHardwareKeyboard: true
[BaseDriver] Creating session with MJSONWP desired capabilities: {"appActivity":".MainActivi...
[BaseDriver] The following capabilities were provided, but are not recognized by appium: connectHardwareKeyboard.
[BaseDriver] Session created with session id: b8923d16-7e1d-42a2-ba44-07c5738a5cc8
[AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 1.8.0_131
[ADB] Checking whether adb is present
[ADB] Found 1 'build-tools' folders under 'D:\adt-bundle-windows-x86_64-20140702\sdk' (newest first):
[ADB] D:/adt-bundle-windows-x86_64-20140702/sdk/build-tools/android-4.4W
[ADB] Using adb.exe from D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe
[AndroidDriver] Retrieving device list
[ADB] Trying to find a connected android device
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[AndroidDriver] Looking for a device with Android '5.1.1'
[ADB] Setting device id to JTJ4C15B02036806
[ADB] Getting device platform version
[ADB] Running 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe -P 5037 -s JTJ4C15B02036806 shell getprop ro.build.version.release'
[ADB] Current device property 'ro.build.version.release': 5.1.1
[AndroidDriver] Using device: JTJ4C15B02036806
[ADB] Setting device id to JTJ4C15B02036806
[ADB] Running 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe -P 5037 -s JTJ4C15B02036806 shell getprop ro.build.version.sdk'
[ADB] Current device property 'ro.build.version.sdk': 22
[ADB] Device API level: 22
[AndroidDriver] No app sent in, not parsing package/activity
[ADB] Getting device platform version
[ADB] Running 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe -P 5037 -s JTJ4C15B02036806 shell getprop ro.build.version.release'
[ADB] Current device property 'ro.build.version.release': 5.1.1
[ADB] Running 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe -P 5037 -s JTJ4C15B02036806 shell wm size'
[ADB] Running 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe -P 5037 -s JTJ4C15B02036806 shell wm density'
[ADB] Running 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe -P 5037 -s JTJ4C15B02036806 shell getprop ro.product.model'
[ADB] Current device property 'ro.product.model': SCL-TL00H
[ADB] Running 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe -P 5037 -s JTJ4C15B02036806 shell getprop ro.product.manufacturer'
[ADB] Current device property 'ro.product.manufacturer': HUAWEI
[ADB] Device API level: 22
[ADB] Running 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe -P 5037 -s JTJ4C15B02036806 shell am force-stop io.appium.uiautomator2.server'
[ADB] Checking app cert for C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v1.12.0.apk
[ADB] Cannot use apksigner tool for signature verification. Defaulting to verify.jar. Original error: Could not find apksigner.bat in D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\apksigner.bat,D:\adt-bundle-windows-x86_64-20140702\sdk\emulator\apksigner.bat,D:\adt-bundle-windows-x86_64-20140702\sdk\tools\apksigner.bat,D:\adt-bundle-windows-x86_64-20140702\sdk\tools\bin\apksigner.bat,D:\adt-bundle-windows-x86_64-20140702\sdk\build-tools\android-4.4W\apksigner.bat. Do you have the Android SDK installed at 'D:\adt-bundle-windows-x86_64-20140702\sdk'?
[ADB] 'C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v1.12.0.apk' is not signed with debug cert.
[ADB] Signing 'C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v1.12.0.apk' with default cert
[ADB] Cannot use apksigner tool for signing. Defaulting to sign.jar. Original error: Could not find apksigner.bat in D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\apksigner.bat,D:\adt-bundle-windows-x86_64-20140702\sdk\emulator\apksigner.bat,D:\adt-bundle-windows-x86_64-20140702\sdk\tools\apksigner.bat,D:\adt-bundle-windows-x86_64-20140702\sdk\tools\bin\apksigner.bat,D:\adt-bundle-windows-x86_64-20140702\sdk\build-tools\android-4.4W\apksigner.bat. Do you have the Android SDK installed at 'D:\adt-bundle-windows-x86_64-20140702\sdk'?
[ADB] Resigning apk.
[UiAutomator2] Deleting UiAutomator2 session
[UiAutomator2] Deleting UiAutomator2 server session
[UiAutomator2] Did not get confirmation UiAutomator2 deleteSession worked; Error was: Error: Trying to proxy a session command without session id
[ADB] Running 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe -P 5037 -s JTJ4C15B02036806 shell am force-stop com.example.hrst.mycalcutor'
[ADB] Removing forwarded port socket connection: 8200
[ADB] Running 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe -P 5037 -s JTJ4C15B02036806 forward --remove tcp:8200'
[ADB] Running 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe -P 5037 -s JTJ4C15B02036806 forward --remove tcp:8200'
[UiAutomator2] Unable to remove port forward 'Error executing adbExec. Original error: 'Command 'D:\adt-bundle-windows-x86_64-20140702\sdk\platform-tools\adb.exe -P 5037 -s JTJ4C15B02036806 forward --remove tcp:8200' exited with code 1'; Stderr: 'error: cannot remove listener
[UiAutomator2] error: cannot remove listener'; Code: '1''
[BaseDriver] Event 'newSessionStarted' logged at 1532530308617 (22:51:48 GMT+0800 (中国标准时间))
[MJSONWP] Encountered internal error running command: Error: Could not sign with default certificate. Original error Command ''D:\Program Files\Java\jdk1.8.0_131\bin\java.exe' -jar 'C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-adb\jars\sign.jar' 'C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v1.12.0.apk' --override' exited with code 1
[MJSONWP] at ADB.callee$0$0$ (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\appium-adb\lib\tools\apk-signing.js:79:13)
[MJSONWP] at tryCatch (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
[MJSONWP] at GeneratorFunctionPrototype.invoke as _invoke
[MJSONWP] at GeneratorFunctionPrototype.prototype.(anonymous function) as throw
[MJSONWP] at GeneratorFunctionPrototype.invoke (C:\Program Files (x86)\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[MJSONWP] at
[HTTP] <-- POST /wd/hub/session 500 14079 ms - 616
[HTTP]

共收到 8 条回复 时间 点赞

我也遇到这个问题了。关注一下

Rong Che 回复

我重新装 Android SDK 后,就正常了。

你好,遇到同样的问题,请问 sdk 怎么重新安装的,我重新安装了还是没有这个 apksigner.bat

这个问题我也遇到
1.更新安装 sdk
2.管理员打开 appium 再执行(执行前两步我就能运行了)
如果不行试试这方法,我就没尝试了
3.把这个把 jdk、安卓 sdk 移动到其他盘里,看下面这个链接说好像是这样就能解决的
https://stackoverflow.com/questions/51877845/appium-desktop-server-error-when-starting-session-could-not-sign-with-default-ce
https://stackoverflow.com/questions/24904945/command-prompt-error-c-program-is-not-recognized-as-an-internal-or-external-c

梁亮亮 回复

打开 SDK Manager,更新最新的 Android SDK Build-Tools,SDK Tools。

我也碰到这个问题,重装 sdk 没有解决,求解````

我是把 appium 版本安装为 1.8 之后就解决了 同样的代码

更新到最新的没什么用

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册