Appium ADB 错误:当设备通过端口 5555 上的 tcpip 连接时,获取设备平台版本时出错

Posted

技术标签:

【中文标题】Appium ADB 错误:当设备通过端口 5555 上的 tcpip 连接时,获取设备平台版本时出错【英文标题】:Appium ADB Error: Error getting device platform version , when device is connected via tcpip on port 5555 【发布时间】:2021-05-26 13:43:52 【问题描述】:

我已经通过端口 5555 上的 tcpip 无线连接了 android 设备。 当我运行命令“adb devices”时,我得到以下输出

附加设备列表

172.16.202.156:5555 设备

现在,我正在使用以下功能在同一设备上运行 appium 测试用例

"appPackage": "com.***.",

"uiautomator2ServerInstallTimeout": "500000",

“设备名称”:“172.16.202.156:5555”,

"appActivity": "********.SplashActivity",

"androidInstallTimeout": "500000",

"nativeInstrumentsLib": "true",

"newCommandTimeout": "500",

"adbExecTimeout": "520000",

"platformVersion": "9",

"automationName": "UiAutomator2",

"浏览器名称": "",

"waitForAppScript": "$.delay(5000);",

"platformName": "Android",

“autoAcceptAlerts”:“真”

我在 appium 服务器日志中的 adb 命令出现错误。

[debug] [35m[MJSONWP][39m 运行命令遇到内部错误:Error: Error getting device platform version.原始错误:执行 adbExec 时出错。原始错误:'Command '/Users/mac1/Library/Android/sdk/platform-tools/adb -P 5037 -s 172.16.202.156:5555 shell getprop ro.build.version.release' exited with code 1'; Stderr: '错误:未知的主机服务';代码:'1' [调试] [35m [MJSONWP] [39m at ADB.getPlatformVersion (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-adb/lib/tools/adb-commands.js:122: 11) [debug] [35m[MJSONWP][39m 破坏套接字连接

这里是完整的 appium 服务器日志。

[info] [35m[Appium][39m Welcome to Appium v1.17.1
[info] [35m[Appium][39m Non-default server args:
[info] [35m[Appium][39m   allowInsecure: 
[info] [35m[Appium][39m   
[info] [35m[Appium][39m   denyInsecure: 
[info] [35m[Appium][39m   
[info] [35m[Appium][39m Appium REST http interface listener started on 0.0.0.0:4723[info] [35m[HTTP][39m [37m-->[39m [37mGET[39m [37m/wd/hub/status[39m
[info] [35m[HTTP][39m [90m[39m
[debug] [35m[GENERIC][39m Calling AppiumDriver.getStatus() with args: []
[debug] [35m[GENERIC][39m Responding to client with driver.getStatus() result: "build":"version":"1.17.1"
[info] [35m[HTTP][39m [37m<-- GET /wd/hub/status [39m[32m200[39m [90m9 ms - 68[39m
[info] [35m[HTTP][39m [90m[39m
[info] [35m[HTTP][39m [37m-->[39m [37mGET[39m [37m/wd/hub/status[39m
[info] [35m[HTTP][39m [90m[39m
[debug] [35m[GENERIC][39m Calling AppiumDriver.getStatus() with args: []
[debug] [35m[GENERIC][39m Responding to client with driver.getStatus() result: "build":"version":"1.17.1"
[info] [35m[HTTP][39m [37m<-- GET /wd/hub/status [39m[32m200[39m [90m2 ms - 68[39m
[info] [35m[HTTP][39m [90m[39m[info] [35m[HTTP][39m [37m-->[39m [37mPOST[39m [37m/wd/hub/session[39m
[info] [35m[HTTP][39m [90m"capabilities":"desiredCapabilities":"appPackage":"com.********.******","uiautomator2ServerInstallTimeout":"500000","deviceName":"172.16.202.156:5555","appActivity":"crc646c9a2553fa37f659.SplashActivity","androidInstallTimeout":"500000","nativeInstrumentsLib":"true","newCommandTimeout":"500","adbExecTimeout":"520000","platformVersion":"9","automationName":"UiAutomator2","browserName":"","waitForAppScript":"$.delay(5000);","platformName":"Android","autoAcceptAlerts":"true","requiredCapabilities":,"desiredCapabilities":"appPackage":"com.********.******","uiautomator2ServerInstallTimeout":"500000","deviceName":"172.16.202.156:5555","appActivity":"crc646c9a2553fa37f659.SplashActivity","androidInstallTimeout":"500000","nativeInstrumentsLib":"true","newCommandTimeout":"500","adbExecTimeout":"520000","platformVersion":"9","automationName":"UiAutomator2","browserName":"","waitForAppScript":"$.delay(5000);","platformName":"Android","autoAcceptAlerts":"true","requiredCapabilities":[39m
[debug] [35m[W3C][39m Calling AppiumDriver.createSession() with args: ["appPackage":"com.********.******","uiautomator2ServerInstallTimeout":"500000","deviceName":"172.16.202.156:5555","appActivity":"crc646c9a2553fa37f659.SplashActivity","androidInstallTimeout":"500000","nativeInstrumentsLib":"true","newCommandTimeout":"500","adbExecTimeout":"520000","platformVersion":"9","automationName":"UiAutomator2","browserName":"","waitForAppScript":"$.delay(5000);","platformName":"Android","autoAcceptAlerts":"true",,"desiredCapabilities":"appPackage":"com.********.******","uiautomator2ServerInstallTimeout":"500000","deviceName":"172.16.202.156:5555","appActivity":"crc646c9a2553fa37f659.SplashActivity","androidInstallTimeout":"500000","nativeInstrumentsLib":"true","newCommandTimeout":"500","adbExecTimeout":"520000","platformVersion":"9","automationName":"UiAutomator2","browserName":"","waitForAppScript":"$.delay(5000);","platformName":"Android","autoAcceptAlerts":"true","requiredCapabilities":]
[debug] [35m[BaseDriver][39m Event 'newSessionRequested' logged at 1614153815161 (08:03:35 GMT+0000 (Coordinated Universal Time))
[info] [35m[Appium][39m Appium v1.17.1 creating new AndroidUiautomator2Driver (v1.44.2) session
[debug] [35m[BaseDriver][39m Creating session with MJSONWP desired capabilities: 
[debug] [35m[BaseDriver][39m   "appPackage": "com.********.******",
[debug] [35m[BaseDriver][39m   "uiautomator2ServerInstallTimeout": "500000",
[debug] [35m[BaseDriver][39m   "deviceName": "172.16.202.156:5555",
[debug] [35m[BaseDriver][39m   "appActivity": "crc646c9a2553fa37f659.SplashActivity",
[debug] [35m[BaseDriver][39m   "androidInstallTimeout": "500000",
[debug] [35m[BaseDriver][39m   "nativeInstrumentsLib": "true",
[debug] [35m[BaseDriver][39m   "newCommandTimeout": "500",
[debug] [35m[BaseDriver][39m   "adbExecTimeout": "520000",
[debug] [35m[BaseDriver][39m   "platformVersion": "9",
[debug] [35m[BaseDriver][39m   "automationName": "UiAutomator2",
[debug] [35m[BaseDriver][39m   "browserName": "",
[debug] [35m[BaseDriver][39m   "waitForAppScript": "$.delay(5000);",
[debug] [35m[BaseDriver][39m   "platformName": "Android",
[debug] [35m[BaseDriver][39m   "autoAcceptAlerts": "true"
[debug] [35m[BaseDriver][39m 
[warn] [35m[BaseDriver][39m Capability 'newCommandTimeout' changed from string ('500') to integer (500). This may cause unexpected behavior
[warn] [35m[BaseDriver][39m Capability 'uiautomator2ServerInstallTimeout' changed from string ('500000') to integer (500000). This may cause unexpected behavior
[warn] [35m[BaseDriver][39m Capability 'androidInstallTimeout' changed from string ('500000') to integer (500000). This may cause unexpected behavior
[warn] [35m[BaseDriver][39m Capability 'adbExecTimeout' changed from string ('520000') to integer (520000). This may cause unexpected behavior
[warn] [35m[BaseDriver][39m The following capabilities were provided, but are not recognized by Appium:
[warn] [35m[BaseDriver][39m   nativeInstrumentsLib
[warn] [35m[BaseDriver][39m   waitForAppScript
[warn] [35m[BaseDriver][39m   autoAcceptAlerts
[info] [35m[BaseDriver][39m Session created with session id: 8fea8be0-33b8-4fca-8d01-39121a8731ae
[info] [35m[UiAutomator2][39m Starting 'com.********.******' directly on the device[info] [35m[ADB][39m Found 2 'build-tools' folders under '/Users/mac1/Library/Android/sdk' (newest first):
[info] [35m[ADB][39m     /Users/mac1/Library/Android/sdk/build-tools/30.0.0
[info] [35m[ADB][39m     /Users/mac1/Library/Android/sdk/build-tools/28.0.3
[info] [35m[ADB][39m Using 'adb' from '/Users/mac1/Library/Android/sdk/platform-tools/adb'
[info] [35m[AndroidDriver][39m Retrieving device list
[debug] [35m[ADB][39m Trying to find a connected android device
[debug] [35m[ADB][39m Getting connected devices...
[debug] [35m[ADB][39m Connected devices: ["udid":"172.16.202.156:5555","state":"device"]
[info] [35m[AndroidDriver][39m Looking for a device with Android '9.0.0'
[debug] [35m[ADB][39m Setting device id to 172.16.202.156:5555
[info] [35m[ADB][39m Getting device platform version
[debug] [35m[ADB][39m Running '/Users/mac1/Library/Android/sdk/platform-tools/adb -P 5037 -s 172.16.202.156\:5555 shell getprop ro.build.version.release'
[debug] [35m[UiAutomator2][39m Deleting UiAutomator2 session
[debug] [35m[BaseDriver][39m Event 'newSessionStarted' logged at 1614153815988 (08:03:35 GMT+0000 (Coordinated Universal Time))
[debug] [35m[MJSONWP][39m Encountered internal error running command: Error: Error getting device platform version. Original error: Error executing adbExec. Original error: 'Command '/Users/mac1/Library/Android/sdk/platform-tools/adb -P 5037 -s 172.16.202.156\:5555 shell getprop ro.build.version.release' exited with code 1'; Stderr: 'error: unknown host service'; Code: '1'
[debug] [35m[MJSONWP][39m     at ADB.getPlatformVersion (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-adb/lib/tools/adb-commands.js:122:11)
[debug] [35m[MJSONWP][39m Destroying socket connection
[info] [35m[HTTP][39m [37m<-- POST /wd/hub/session [39m[31m500[39m [90m893 ms - 436[39m
[info] [35m[HTTP][39m [90m[39m[info] [35m[HTTP][39m [37m-->[39m [37mPOST[39m [37m/wd/hub/session[39m
[info] [35m[HTTP][39m [90m"desiredCapabilities":"appPackage":"com.********.******","uiautomator2ServerInstallTimeout":"500000","deviceName":"172.16.202.156:5555","appActivity":"crc646c9a2553fa37f659.SplashActivity","androidInstallTimeout":"500000","nativeInstrumentsLib":"true","newCommandTimeout":"500","adbExecTimeout":"520000","platformVersion":"9","automationName":"UiAutomator2","browserName":"","waitForAppScript":"$.delay(5000);","platformName":"Android","autoAcceptAlerts":"true","requiredCapabilities":[39m
[debug] [35m[MJSONWP][39m Calling AppiumDriver.createSession() with args: ["appPackage":"com.********.******","uiautomator2ServerInstallTimeout":"500000","deviceName":"172.16.202.156:5555","appActivity":"crc646c9a2553fa37f659.SplashActivity","androidInstallTimeout":"500000","nativeInstrumentsLib":"true","newCommandTimeout":"500","adbExecTimeout":"520000","platformVersion":"9","automationName":"UiAutomator2","browserName":"","waitForAppScript":"$.delay(5000);","platformName":"Android","autoAcceptAlerts":"true",,null]
[debug] [35m[BaseDriver][39m Event 'newSessionRequested' logged at 1614153816119 (08:03:36 GMT+0000 (Coordinated Universal Time))
[info] [35m[Appium][39m Appium v1.17.1 creating new AndroidUiautomator2Driver (v1.44.2) session
[debug] [35m[BaseDriver][39m Creating session with MJSONWP desired capabilities: 
[debug] [35m[BaseDriver][39m   "appPackage": "com.********.******",
[debug] [35m[BaseDriver][39m   "uiautomator2ServerInstallTimeout": "500000",
[debug] [35m[BaseDriver][39m   "deviceName": "172.16.202.156:5555",
[debug] [35m[BaseDriver][39m   "appActivity": "crc646c9a2553fa37f659.SplashActivity",
[debug] [35m[BaseDriver][39m   "androidInstallTimeout": "500000",
[debug] [35m[BaseDriver][39m   "nativeInstrumentsLib": "true",
[debug] [35m[BaseDriver][39m   "newCommandTimeout": "500",
[debug] [35m[BaseDriver][39m   "adbExecTimeout": "520000",
[debug] [35m[BaseDriver][39m   "platformVersion": "9",
[debug] [35m[BaseDriver][39m   "automationName": "UiAutomator2",
[debug] [35m[BaseDriver][39m   "browserName": "",
[debug] [35m[BaseDriver][39m   "waitForAppScript": "$.delay(5000);",
[debug] [35m[BaseDriver][39m   "platformName": "Android",
[debug] [35m[BaseDriver][39m   "autoAcceptAlerts": "true"
[debug] [35m[BaseDriver][39m 
[warn] [35m[BaseDriver][39m Capability 'newCommandTimeout' changed from string ('500') to integer (500). This may cause unexpected behavior
[warn] [35m[BaseDriver][39m Capability 'uiautomator2ServerInstallTimeout' changed from string ('500000') to integer (500000). This may cause unexpected behavior
[warn] [35m[BaseDriver][39m Capability 'androidInstallTimeout' changed from string ('500000') to integer (500000). This may cause unexpected behavior
[warn] [35m[BaseDriver][39m Capability 'adbExecTimeout' changed from string ('520000') to integer (520000). This may cause unexpected behavior
[warn] [35m[BaseDriver][39m The following capabilities were provided, but are not recognized by Appium:
[warn] [35m[BaseDriver][39m   nativeInstrumentsLib
[warn] [35m[BaseDriver][39m   waitForAppScript
[warn] [35m[BaseDriver][39m   autoAcceptAlerts
[info] [35m[BaseDriver][39m Session created with session id: e854d697-1ed0-481c-b353-0f31eca49d97
[info] [35m[UiAutomator2][39m Starting 'com.********.******' directly on the device
[info] [35m[ADB][39m Using 'adb' from '/Users/mac1/Library/Android/sdk/platform-tools/adb'
[info] [35m[AndroidDriver][39m Retrieving device list
[debug] [35m[ADB][39m Trying to find a connected android device
[debug] [35m[ADB][39m Getting connected devices...
[debug] [35m[ADB][39m Connected devices: ["udid":"172.16.202.156:5555","state":"device"]
[info] [35m[AndroidDriver][39m Looking for a device with Android '9.0.0'
[debug] [35m[ADB][39m Setting device id to 172.16.202.156:5555
[info] [35m[ADB][39m Getting device platform version
[debug] [35m[ADB][39m Running '/Users/mac1/Library/Android/sdk/platform-tools/adb -P 5037 -s 172.16.202.156\:5555 shell getprop ro.build.version.release'
[debug] [35m[UiAutomator2][39m Deleting UiAutomator2 session
[debug] [35m[BaseDriver][39m Event 'newSessionStarted' logged at 1614153816179 (08:03:36 GMT+0000 (Coordinated Universal Time))
[debug] [35m[MJSONWP][39m Encountered internal error running command: Error: Error getting device platform version. Original error: Error executing adbExec. Original error: 'Command '/Users/mac1/Library/Android/sdk/platform-tools/adb -P 5037 -s 172.16.202.156\:5555 shell getprop ro.build.version.release' exited with code 1'; Stderr: 'error: unknown host service'; Code: '1'
[debug] [35m[MJSONWP][39m     at ADB.getPlatformVersion (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-adb/lib/tools/adb-commands.js:122:11)
[debug] [35m[MJSONWP][39m Destroying socket connection
[info] [35m[HTTP][39m [37m<-- POST /wd/hub/session [39m[31m500[39m [90m63 ms - 436[39m
[info] [35m[HTTP][39m [90m[39m
[info] [35m[HTTP][39m [37m-->[39m [37mPOST[39m [37m/wd/hub/session[39m
[info] [35m[HTTP][39m [90m"capabilities":"desiredCapabilities":"appPackage":"com.*******.***","uiautomator2ServerInstallTimeout":"500000","deviceName":"172.16.202.156:5555","appActivity":"crc646c9a2553fa37f659.SplashActivity","androidInstallTimeout":"500000","nativeInstrumentsLib":"true","newCommandTimeout":"500","adbExecTimeout":"520000","platformVersion":"9","automationName":"UiAutomator2","browserName":"","waitForAppScript":"$.delay(5000);","platformName":"Android","autoAcceptAlerts":"true","requiredCapabilities":[39m
[debug] [35m[W3C][39m Calling AppiumDriver.createSession() with args: [null,null,"desiredCapabilities":"appPackage":"com.********.******","uiautomator2ServerInstallTimeout":"500000","deviceName":"172.16.202.156:5555","appActivity":"crc646c9a2553fa37f659.SplashActivity","androidInstallTimeout":"500000","nativeInstrumentsLib":"true","newCommandTimeout":"500","adbExecTimeout":"520000","platformVersion":"9","automationName":"UiAutomator2","browserName":"","waitForAppScript":"$.delay(5000);","platformName":"Android","autoAcceptAlerts":"true","requiredCapabilities":]
[debug] [35m[BaseDriver][39m Event 'newSessionRequested' logged at 1614153816188 (08:03:36 GMT+0000 (Coordinated Universal Time))
[debug] [35m[BaseDriver][39m Event 'newSessionStarted' logged at 1614153816189 (08:03:36 GMT+0000 (Coordinated Universal Time))
[debug] [35m[W3C][39m Encountered internal error running command: Error: Either JSONWP or W3C capabilities should be provided
[debug] [35m[W3C][39m     at parseCapsForInnerDriver (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/lib/utils.js:58:14)
[debug] [35m[W3C][39m     at AppiumDriver.createSession (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/lib/appium.js:296:26)
[debug] [35m[W3C][39m     at commandExecutor (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/driver.js:330:9)
[debug] [35m[W3C][39m     at AppiumDriver.executeCommand (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/driver.js:344:15)
[debug] [35m[W3C][39m     at AppiumDriver.executeCommand (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/lib/appium.js:520:26)
[debug] [35m[W3C][39m     at asyncHandler (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:309:34)
[debug] [35m[W3C][39m     at /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:447:15
[debug] [35m[W3C][39m     at Layer.handle [as handle_request] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
[debug] [35m[W3C][39m     at next (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/express/lib/router/route.js:137:13)
[debug] [35m[W3C][39m     at Route.dispatch (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/express/lib/router/route.js:112:3)
[debug] [35m[W3C][39m     at Layer.handle [as handle_request] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
[debug] [35m[W3C][39m     at /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/express/lib/router/index.js:281:22
[debug] [35m[W3C][39m     at Function.process_params (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/express/lib/router/index.js:335:12)
[debug] [35m[W3C][39m     at next (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/express/lib/router/index.js:275:10)
[debug] [35m[W3C][39m     at logger (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/morgan/index.js:144:5)
[debug] [35m[W3C][39m     at Layer.handle [as handle_request] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/express/lib/router/layer.js:95:5)
[debug] [35m[W3C][39m     at trim_prefix (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/express/lib/router/index.js:317:13)
[debug] [35m[W3C][39m     at /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/express/lib/router/index.js:284:7
[debug] [35m[W3C][39m     at Function.process_params (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/express/lib/router/index.js:335:12)
[debug] [35m[W3C][39m     at next (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/express/lib/router/index.js:275:10)
[debug] [35m[W3C][39m     at /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/body-parser/lib/read.js:130:5
[debug] [35m[W3C][39m     at invokeCallback (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/raw-body/index.js:224:16)
[debug] [35m[W3C][39m     at done (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/raw-body/index.js:213:7)
[debug] [35m[W3C][39m     at IncomingMessage.onEnd (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/raw-body/index.js:273:7)
[debug] [35m[W3C][39m     at IncomingMessage.emit (events.js:208:15)
[debug] [35m[W3C][39m     at endReadableNT (_stream_readable.js:1168:12)
[debug] [35m[W3C][39m     at processTicksAndRejections (internal/process/task_queues.js:77:11)
[debug] [35m[W3C][39m Destroying socket connection
[info] [35m[HTTP][39m [37m<-- POST /wd/hub/session [39m[31m500[39m [90m55 ms - 667[39m
[info] [35m[HTTP][39m [90m[39m

【问题讨论】:

【参考方案1】:

这可能是这个已知问题:https://github.com/appium/appium/issues/12736(他们责怪adb 而不是承认)。你能跑adb shell getprop ro.build.version.release吗?

【讨论】:

当我运行“adb shell getprop ro.build.version.release”命令时返回“8.1.0”

以上是关于Appium ADB 错误:当设备通过端口 5555 上的 tcpip 连接时,获取设备平台版本时出错的主要内容,如果未能解决你的问题,请参考以下文章

appium-电脑连不上手机设备如何解决

appium之adb常用命令

appium adb端口被占用问题

Appium连接mumu安卓模拟器(真机)自动化测试

如何通过adb实现两个设备的数据传输(adb forward基本原理)

(appium+python)UI自动化_10_adb常用命令