在CircleCI中使用Detox构建iOS时遇AppleSimUtils问题
问题复现
在CircleCI macOS执行器配置iOS Detox构建时,执行命令applesimutils --list byId='SIM_ID'失败,报错:
Error: The data couldn’t be read because it isn’t in the correct format.. See “applesimutils --help” for usage.
Error: Unable to obtain a list of simulators. See “applesimutils --help” for usage.
本地执行该命令可正常获取结果。
排查解决步骤
对齐AppleSimUtils版本
不同Xcode版本对AppleSimUtils有兼容性要求,确保CircleCI环境安装的版本与本地一致。可通过brew指定版本安装:brew install wix/brew/applesimutils@X.X.X
执行applesimutils --version对比本地与CircleCI环境的版本号。配置Xcode及模拟器环境
CircleCI默认环境可能未正确初始化Xcode或模拟器:- 指定Xcode版本:
xcode-select -s /Applications/Xcode_XX.X.app - 提前创建并启动目标模拟器:
xcrun simctl create "iPhone 14" com.apple.CoreSimulator.SimDeviceType.iPhone-14 com.apple.CoreSimulator.SimRuntime.iOS-XX.X xcrun simctl boot <SIM_ID>
- 指定Xcode版本:
修正命令参数格式
CircleCI环境中引号转义可能导致参数解析错误,尝试调整命令格式:applesimutils --list "byId=<SIM_ID>"验证模拟器存在性
执行Detox命令前,先确认目标模拟器ID在CircleCI环境中存在:xcrun simctl list devices
内容的提问来源于stack exchange,提问作者Kaushil Ruparelia

