`flutter build ios` fails at PhaseScriptExecution even on empty project, but building from within Xcode succeeds

1,371 views
Skip to first unread message

David Dávila

unread,
Apr 6, 2022, 6:59:14 PM4/6/22
to Flutter Development (flutter-dev)
I'm facing a very strange issue that I don't necessarily think yet is a bug on the Flutter build system, but I have no idea what else it could be. So I'm not filing an issue yet, instead I want to yell a little call for help or clues first:

The short version is that
  • both flutter build ios and xcodebuild -target Runner always fail with a "Command PhaseScriptExecution failed with a nonzero exit code" but building the corresponding Runner project from within Xcode always succeeds.
  • this only happens in one of three machines in which I'm testing, the three of them are Apple Silicon-based and are running the same (currently latest) versions of macOS, Flutter, Dart, DevTools, Xcode and CocoaPods.
  • this is reproducible with an empty Flutter project

This is the longer version:

I'm failing to have one of three Macs succeed at flutter build ios, even though if I open the Runner project Xcode will succeed at building the Runner target (for either the iOS simulator or "Any iOS device (arm64, armv7"). The other two Macs succeed at building from the CLI or from within Xcode. The project itself does not seem to matter, it will fail the same with a large production project or with an empty project (I will elaborate below).

All three are Apple Silicon machines and are in the same versions of macOS (12.3.1), Flutter (2.10.4), Xcode (13.3 - 13E113) and Cocoapods (1.11.3). They all have access to the same development team, certificates and profiles (again, the build succeeds when triggered through the Xcode's UI).

The build phase that fails is the script execution ("Command PhaseScriptExecution failed with a nonzero exit code"). 

The script that fails is: 
/bin/sh 
"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build

Here is how I reproduce the failure in the machine where it fails:

First I make a fresh install of Flutter itself (Download flutter_macos_2.10.4-stable.zip from docs.flutter.dev > Get started > Install, extract it to my installation path, ensure my $PATH includes my/installation/path/flutter/bin, and that which flutter answers my/installation/path/flutter/bin/flutter). After installation, this is what flutter doctor -v outputs:

Running "flutter pub get" in flutter_tools... 5.7s
[✓] Flutter (Channel stable, 2.10.4, on macOS 12.3.1 21E258 darwin-arm, locale en-IE)
• Flutter version 2.10.4 at /Users/administrator/dev/flutter
• Framework revision c860cba910 (13 days ago), 2022-03-25 00:23:12 -0500
• Engine revision 57d3bac3dd
• Dart version 2.16.2
• DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc5)
• Android SDK at /Users/administrator/Library/Android/sdk
• Platform android-31, build-tools 31.0.0-rc5
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.3

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 4.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
• Dart plugin can be installed from:
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[!] Connected device
! No devices available

[✓] HTTP Host Availability
• All required HTTP hosts are available

Then I create an empty Flutter project with flutter create my_empty_project, open my_empty_project/ios/Runner.xcworkspace on Xcode, select the Runner project in the navigator, then select the Runner target and the "Signing & Capabilities" tab, and ensure "Automatically manage signing" is checked and a valid Team is selected, and change the bundle identifier to something legal.

Back to the CLI, I run flutter build ios. The build fails, this is an excerpt of the output (full output available on demand!)

** BUILD FAILED **


Xcode's output:
Writing result bundle at path:
/var/folders/54/5blnz30j33df6h14mnyn_8_w0000gn/T/flutter_tools.6FOHNH/flutter_ios_build_temp_dirQaqxN9/temporary_xcresult_b
undle


Failed to package /Users/administrator/my_empty_project.
Command PhaseScriptExecution failed with a nonzero exit code
note: Using new build system
note: Planning
note: Build preparation complete
note: Building targets in dependency order

Out of curiosity I tried to build with xcodebuild, and it failed too: If I do an xcodebuild -target Runner from within the ios/ directory, the build will fail with a similar error (full build log available on demand):

** BUILD FAILED **


The following build commands failed:
PhaseScriptExecution Run\ Script /Users/administrator/my_empty_project/ios/build/Runner.build/Release-iphoneos/Runner.build/Script-9740EEB61CF901F6004384FC.sh (in target 'Runner' from project 'Runner')
(1 failure)

Curious about what that failing script is, I cat /Users/administrator/my_empty_project/ios/build/Runner.build/Release-iphoneos/Runner.build/Script-9740EEB61CF901F6004384FC.sh ,which yields the following:

#!/bin/sh
/bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build

What is really puzzling for me is that triggering the build from the Xcode's UI (after opening Runner.xcworkspace) results in a successful build. Full output here also available on demand.

Any clues what this all could be about?

Thank you for reading all the way to here.
Best,
David
Reply all
Reply to author
Forward
0 new messages