iOS17与Xcode15:模拟器及SwiftUI预览启动即崩溃求助
解决方案
1. 彻底清理CoreSimulator缓存与权限
- 先关掉Xcode和所有模拟器相关进程:
killall Xcode killall Simulator killall com.apple.CoreSimulator.CoreSimulatorService - 删除CoreSimulator缓存目录,同时重置开发者目录权限:
rm -rf ~/Library/Developer/CoreSimulator sudo chown -R $(whoami):staff ~/Library/Developer - 重置模拟器设备列表:
xcrun simctl erase all xcrun simctl list devices
2. 清理重复SDK并重新注册Xcode
- 先检查是否存在重复的iOS SDK:
ls /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs - 如果看到多个
iPhoneOS17*.sdk文件,只保留最新版本,删除其余(把下面命令里的iPhoneOS17.x.sdk换成实际要删的旧版本):sudo rm -rf /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.x.sdk - 重新注册Xcode命令行工具并初始化:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer xcodebuild -runFirstLaunch
3. 手动修复liblaunch_sim缺失问题
- 从Xcode的iOS Runtime包中复制缺失的文件到模拟器目录(自动匹配第一个iOS17模拟器设备):
SIM_DEVICE_ID=$(xcrun simctl list devices | grep "iOS 17" | head -n1 | awk '{print $4}' | tr -d '()') cp /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/liblaunch_sim.dylib ~/Library/Developer/CoreSimulator/Devices/$SIM_DEVICE_ID/data/usr/lib/system/ - 修复文件权限:
sudo chmod 755 ~/Library/Developer/CoreSimulator/Devices/$SIM_DEVICE_ID/data/usr/lib/system/liblaunch_sim.dylib sudo chown root:wheel ~/Library/Developer/CoreSimulator/Devices/$SIM_DEVICE_ID/data/usr/lib/system/liblaunch_sim.dylib
4. 验证修复结果
- 重新打开Xcode,新建空白SwiftUI项目
- 尝试启动模拟器,检查SwiftUI预览是否正常加载
- 可以实时查看CoreSimulator日志确认错误是否消除:
tail -f ~/Library/Logs/CoreSimulator/CoreSimulator.log
内容的提问来源于stack exchange,提问作者bacata.borisov
相关产品推荐
相关产品推荐

