iOS设备运行Appium启动会话失败,报错xcodebuild返回码65
问题描述
已在iOS设备上成功安装并构建WebDriverAgent,但通过Java代码发起Appium连接时出现以下错误:
Could not start a new session. Response code 500. Message: An unknown server-side error occurred while processing the command. Original error: Unable to launch WebDriverAgent because of xcodebuild failure: xcodebuild failed with code 65.
This usually indicates an issue with the local Xcode setup or WebDriverAgent project configuration or the driver-to-platform version mismatch.
Consider setting 'showXcodeLog' capability to true in order to check the Appium server log for build-related error messages.. Make sure you follow the tutorial at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md. Try to remove the WebDriverAgentRunner application from the device if it is installed and reboot the device.
测试用Java代码:
DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("platformName", "iOS"); capabilities.setCapability("platformVersion", "16.6.1"); capabilities.setCapability("deviceName", ""); capabilities.setCapability("udid", "00008030-000000000"); capabilities.setCapability("xcodeSigningId", "iPhone Developer"); capabilities.setCapability("automationName", "xcuitest"); driver = new IOSDriver(new URL("http://0.0.0.0:4723"), capabilities);
解决步骤
开启详细日志定位根因
在Capabilities中添加showXcodeLog参数,重新运行后查看Appium服务器日志里的具体构建错误信息——代码65只是通用报错,日志里会暴露签名、权限或依赖的具体问题:capabilities.setCapability("showXcodeLog", true);修复签名与设备权限问题
- 确认
xcodeSigningId对应的"iPhone Developer"证书在Xcode中有效,且当前测试设备已添加到开发者账号的设备列表 - 手动打开WebDriverAgent项目(路径一般为
Appium安装目录/node_modules/appium-xcuitest-driver/WebDriverAgent),在Xcode中选择测试设备和对应签名,重新构建一次,确保无签名类报错 - 删除设备上的WebDriverAgentRunner应用,重启设备后再尝试连接
- 确认
补全必要的Capabilities参数
deviceName不能为空,填写设备的实际名称(可在设备设置-通用-关于本机中查看)- 添加
xcodeOrgId参数(开发者团队ID,可在Xcode-设置-账号中查看团队ID):capabilities.setCapability("xcodeOrgId", "你的团队ID");
检查版本兼容性
- 确保Xcode版本支持iOS16.6.1(需Xcode 14.3及以上)
- 更新Appium的xcuitest驱动到最新版本:执行命令
appium driver update xcuitest
内容的提问来源于stack exchange,提问作者ramdev

