Flutter iOS模拟器构建失败,OneSignal扩展报脚本执行错误
解决iOS模拟器构建Flutter应用时OneSignalNotificationServiceExtension的构建失败问题
问题现象
在iOS模拟器上构建Flutter应用时失败,Xcode构建日志仅提示BUILD FAILED;直接通过Xcode构建时,OneSignalNotificationServiceExtension目标报Command PhaseScriptExecution failed with a nonzero exit code错误。
构建错误日志
Launching lib/main.dart on iPhone 16 Pro in debug mode... Running Xcode build... Xcode build done. 37.0s Failed to build iOS app Error output from Xcode build: ↳ --- xcodebuild: WARNING: Using the first of multiple matching destinations: { platform:iOS Simulator, id:5E344FBA-401F-412E-9583-5B2577E3D787, OS:18.3.1, name:iPhone 16 Pro } { platform:iOS Simulator, id:5E344FBA-401F-412E-9583-5B2577E3D787, OS:18.3.1, name:iPhone 16 Pro } ** BUILD FAILED ** Xcode's output: ↳ Writing result bundle at path: /var/folders/_c/n_j3czcj1yb664tp_d_lcxj00000gn/T/flutter_tools.MmK6Hw/flutter_ios_build_temp_dirqmW6eZ/temporary_xcresult_bundle
环境检查结果
flutter doctor无异常:
[✓] Flutter (Channel stable, 3.24.4, on macOS 15.3.1 24D70 darwin-arm64, locale en-US) • Flutter version 3.24.4 on channel stable at /Users/starig/fvm/versions/3.24.4 • Upstream repository https://github.com/flutter/flutter.git • Framework revision 603104015d (4 months ago), 2024-10-24 08:01:25 -0700 • Engine revision db49896cf2 • Dart version 3.5.4 • DevTools version 2.37.3 [✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1) • Android SDK at /Users/starig/Library/Android/sdk • Platform android-35, build-tools 35.0.1 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 21.0.5+-13047016-b750.29) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 16.2) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 16C5032a • CocoaPods version 1.16.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2024.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 21.0.5+-13047016-b750.29) [✓] Connected device (5 available) • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 15 (API 35) (emulator) • iPhone 16 Pro (mobile) • 5E344FBA-401F-412E-9583-5B2577E3D787 • ios • com.apple.CoreSimulator.SimRuntime.iOS-18-3 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 15.3.1 24D70 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 15.3.1 24D70 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 133.0.6943.142 [✓] Network resources • All expected network resources are available. • No issues found!
已尝试的无效操作
flutter cleanpod deintegratepod install
解决方案
针对OneSignal扩展的Run Script错误处理
- 打开Xcode,找到项目中的
OneSignalNotificationServiceExtensiontarget - 切换到Build Phases标签页,找到Run Script阶段
- 修改脚本,让它仅在真机构建时执行(模拟器不需要上传符号表):
在脚本最开头添加判断逻辑:
若不确定脚本内容,可先临时注释掉整个脚本,测试是否能正常构建,确认是脚本导致的问题。if [ "$PLATFORM_NAME" != "iphonesimulator" ]; then # 保留原有的OneSignal脚本内容 fi - 检查Extension的配置一致性:
- 确保
OneSignalNotificationServiceExtension的Deployment Target和主应用的目标版本一致 - 确认Swift Version配置与项目其他部分兼容
- 确保
- 重新执行构建流程:
flutter clean cd ios pod deintegrate pod install cd .. flutter run
内容的提问来源于stack exchange,提问作者Starkov Ivan
相关产品推荐
相关产品推荐

