Xcode27正式版今天发布了,xcode突然跳出来要升级,安装后下载了ios27,新的模拟器运行在Device Hub里面,我使用HBuilderX(版本5.24)运行到IOS模拟器,在设备里面还能看到设备列表,但是点击运行后就提示:
启动模拟器失败:
Command failed: open -a Simulator
Unable to find application named 'Simulator'
根据空白人吗的代码,我整理了一下,可以启动模拟器并且运行了,如下:
在不改动 Xcode 27 原文件的前提下,给DeviceHub.app做一个壳,叫做Simulator.app,当HBuilderX 执行 open -a Simulator 时运行这个壳App,实际上去打开真正的 DeviceHub.app
一、先确认 DeviceHub.app 的实际路径
在终端上运行如下代码,应该会看到DeviceHub.app
ls /Applications/Xcode.app/Contents/Applications/
二、创建壳App的目录结构
终端运行如下代码:
sudo mkdir -p /Applications/Simulator.app/Contents/MacOS
三、创建写入Info.plist文件,告诉macOS这是一个名为Simulator的App
终端运行如下代码:
sudo tee /Applications/Simulator.app/Contents/Info.plist >/dev/null <<'PLIST'
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0"><dict>
<key>CFBundleIdentifier</key><string>local.hbx.simulator-launcher</string>
<key>CFBundleName</key><string>Simulator</string>
<key>CFBundleExecutable</key><string>Simulator</string>
<key>CFBundlePackageType</key><string>APPL</string>
<key>CFBundleVersion</key><string>1</string>
<key>LSUIElement</key><true/>
</dict></plist>
PLIST
四、写入启动脚本,打开Simulator时,实际打开DeviceHub
终端运行如下代码:
sudo tee /Applications/Simulator.app/Contents/MacOS/Simulator >/dev/null <<'SCRIPT'
#!/bin/sh
exec /usr/bin/open "/Applications/Xcode.app/Contents/Applications/DeviceHub.app" "$@"
SCRIPT
五、赋予执行权限
终端运行如下代码:
sudo chmod 755 /Applications/Simulator.app/Contents/MacOS/Simulator
六、让系统注册这个 App
终端运行如下代码:
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f /Applications/Simulator.app
七、测试
终端运行如下代码:
open -a Simulator
八、HBuilderX适配以后删除壳APP
不删也没啥影响,适配以后就不调用Simulator了
1、退出HBuilderX和Device Hub
2、删除Simulator.app
终端运行如下代码:
sudo rm -rf /Applications/Simulator.app
3、主动清掉系统缓存里的残留注册记录
终端运行如下代码:
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f /Applications/Simulator.app 2>/dev/null
4、验证是否删除
终端运行如下代码:
open -a Simulator
3 个回复
1***@qq.com - 前端开发
我也是今天升级后出现这样
空白人吗 - 7年开发经验 可接APP 小程序 网页 后端 vx:wu1020yt
我也出现了, 这个是 xcode 换了 模拟器的名字,
在終端执行以下命令创建一个临时的 Simulator 映射app 即可
(
set -e
target="/Applications/Xcode.app/Contents/Applications/DeviceHub.app"
app="/Applications/Simulator.app"
[ -d "$target" ] || { echo "未找到 Device Hub,请确认 Xcode 安装位置"; exit 1; }
[ ! -e "$app" ] && [ ! -L "$app" ] || { echo "Simulator.app 已存在,停止以避免覆盖"; exit 1; }
sudo mkdir -p "$app/Contents/MacOS"
sudo tee "$app/Contents/Info.plist" >/dev/null <<'PLIST'
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0"><dict>
<key>CFBundleIdentifier</key><string>local.hbx.simulator-launcher</string>
<key>CFBundleName</key><string>Simulator</string>
<key>CFBundleExecutable</key><string>Simulator</string>
<key>CFBundlePackageType</key><string>APPL</string>
<key>CFBundleVersion</key><string>1</string>
<key>LSUIElement</key><true/>
</dict></plist>
PLIST
sudo tee "$app/Contents/MacOS/Simulator" >/dev/null <<'SCRIPT'
!/bin/sh
exec /usr/bin/open "/Applications/Xcode.app/Contents/Applications/DeviceHub.app" "$@"
SCRIPT
sudo chmod 755 "$app/Contents/MacOS/Simulator"
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f "$app"
open -a Simulator
)
yixiaowang
我只升级了系统 目前可以用模拟器