我是小白,最近刚接触 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]


↙↙↙阅读原文可查看相关链接,并与作者交流