You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xcode 13.4构建Flutter项目时Command PhaseScriptExecution返回非零退出码问题求助

Fixing Command PhaseScriptExecution failed with a nonzero exit code in Flutter (Xcode 13.4 + youtube_player_flutter 8.0.0)

First off, let's cut to the chase: your build failure isn't caused by standard Flutter/Xcode issues like cached data or generic version mismatches (you've already tried those!). The root problem is a null-safety compatibility conflict between the youtube_player_flutter:8.0.0 package and your current Flutter version.

Looking at your error log:

../../../../flutter/.pub-cache/hosted/pub.dartlang.org/youtube_player_flutter-8.0.0/lib/src/widgets/youtube_player_builder.dart:51:43: Warning: Operand of null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
final physicalSize = SchedulerBinding.instance?.window.physicalSize;

In newer Flutter versions (3.x+), SchedulerBinding.instance is marked as a non-nullable type—meaning it will never be null. The package's code uses the null-aware ?. operator here, which triggers a warning that eventually breaks the Xcode build process.

Here are the most reliable fixes, ordered by preference:

1. Upgrade to a Compatible Version of youtube_player_flutter

This is the cleanest long-term solution:

  • Open your pubspec.yaml file, find the youtube_player_flutter dependency line.
  • Replace the version 8.0.0 with the latest stable release (as of now, that's ^9.0.0 or higher).
  • Run these commands in your terminal:
    flutter pub upgrade youtube_player_flutter
    flutter clean && flutter pub get
    
  • Try rebuilding your project in Xcode.

2. Manually Patch the Package's Source Code (Temporary Fix)

If you can't upgrade the package right now (e.g., due to project dependencies), you can fix the problematic line directly:

  • Navigate to the file path shown in the error: flutter/.pub-cache/hosted/pub.dartlang.org/youtube_player_flutter-8.0.0/lib/src/widgets/youtube_player_builder.dart
  • Go to line 51, and remove the null-aware operator ? so the line becomes:
    final physicalSize = SchedulerBinding.instance.window.physicalSize;
    
  • Save the file, then run flutter clean && flutter pub get before rebuilding.

3. Align Your Flutter Version with the Package's Requirements

If you're using Flutter 3.x, youtube_player_flutter:8.0.0 isn't fully compatible. You have two options here:

  • Upgrade Flutter: Ensure you're on a stable 3.x release that supports newer package versions.
  • Downgrade the package: Look for a version of youtube_player_flutter that's explicitly compatible with your current Flutter version (check the package's changelog for details).

Bonus Troubleshooting Steps

If the above fixes don't work, double-check these:

  • Make sure Xcode has permission to access your project folder: Go to System Preferences > Security & Privacy > Files and Folders, and ensure Xcode is allowed access to your project directory.
  • Delete Xcode's Derived Data: Open Xcode, go to File > Project Settings > Derived Data, click the arrow to open the folder, delete all contents, then restart Xcode and rebuild.

内容的提问来源于stack exchange,提问作者Vickey Rajak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 18:04:07