I’m trying to run my Flutter App on an iOS 14.4 Simulator and it fails with the following exception:
Launching lib/main.dart on iPhone 12 Pro Max in debug mode...
Running Xcode build...
Xcode build done. 7.1s
Failed to build iOS app
Error output from Xcode build:
↳
** BUILD FAILED **
Xcode's output:
↳
/.../ios/Runner/Runner-Bridging-Header.h:1:9: note: in file included from /.../ios/Runner/Runner-Bridging-Header.h:1:
#import "GeneratedPluginRegistrant.h"
^
/.../ios/Runner/GeneratedPluginRegistrant.h:8:9: error: 'Flutter/Flutter.h' file not found
#import <Flutter/Flutter.h>
^
1 error generated.
<unknown>:0: error: failed to emit precompiled header '/.../Library/Developer/Xcode/DerivedData/Runner-fyllquainthlpefajakayemveuka/Build/Intermediates.noindex/PrecompiledHeaders/Runner-Bridging-Header-swift_3RI409TQ1ULEV-clang_1UAU46DUWBS0C.pch' for bridging header '/.../ios/Runner/Runner-Bridging-Header.h'
/.../ios/Runner/Runner-Bridging-Header.h:1:9: note: in file included from /.../ios/Runner/Runner-Bridging-Header.h:1:
#import "GeneratedPluginRegistrant.h"
^
2 errors generated.
<unknown>:0: error: generate-pch command failed with exit code 1 (use -v to see invocation)
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
Could not build the application for the simulator.
Error launching application on iPhone 12 Pro Max.
This is the output of flutter doctor -v
:
[✓] Flutter (Channel stable, 2.0.1, on macOS 11.1 20C69 darwin-x64, locale en-CA)
• Flutter version 2.0.1 at /.../Applications/flutter
• Framework revision c5a4b4029c (4 days ago), 2021-03-04 09:47:48 -0800
• Engine revision 40441def69
• Dart version 2.12.0
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /.../Library/Android/sdk
• Platform android-30, build-tools 30.0.2
• ANDROID_HOME = /.../Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.4, Build version 12D4e
• CocoaPods version 1.10.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.1)
• 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 1.8.0_242-release-1644-b3-6915495)
[✓] IntelliJ IDEA Ultimate Edition (version 2020.3.2)
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin version 54.0.3
• Dart plugin version 203.7759
[✓] Connected device (4 available)
• Nokia 3 1 Plus (mobile) • ROOGAJG930901259 • android-arm64 • Android 10 (API 29)
• iPhone 8 Plus (mobile) • 49B798DC-F25B-47C5-AAAC-3CFA67822316 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)
• iPhone 12 Pro Max (mobile) • 15D2456A-3E84-4BA1-B579-5E7A4A90AAFA • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 88.0.4324.192
• No issues found!
And my dependencies are the following:
build_runner: ^1.11.5
connectivity: ^3.0.2
crypto: ^3.0.0
cupertino_icons: ^1.0.2
firebase_auth: ^1.0.0
firebase_core: ^1.0.0
firebase_crashlytics: ^1.0.0
firebase_messaging: ^9.0.0
firebase_storage: ^8.0.0
flutter_launcher_icons: ^0.9.0
flutter_native_splash: ^1.0.3
flutter_secure_storage: ^4.0.0
google_fonts: ^2.0.0
http: ^0.13.0
image_picker: ^0.7.2
intl: ^0.17.0
json_annotation: ^4.0.0
json_serializable: ^4.0.2
mqtt_client: ^9.0.0
path_provider: ^2.0.0
pedantic: ^1.11.0
rxdart: ^0.26.0
shared_preferences: ^2.0.3
# soundpool: ^1.1.3
styled_text: ^1.0.3+4
timeago: ^3.0.1
video_player: ^2.0.0
video_compress: ^2.1.1
web_socket_channel: ^1.2.0
The App runs fine on Android, but it fails on iOS. The problem started when I updated Flutter to version 2.0.1. I had tried the following to fix this problem:
- Removed
ios/Flutter/Flutter.podspec
+flutter clean
. pod cache clean --all
+pod install --repo-update
which installs correctly every dependency to their latest version.
Observations:
platform :ios, '12.0'
Well, after much research, I found that in my particular case the
Flutter/Flutter.h
was not being generated, due to an incorrect ordering of theBuild Phases
, and the lack of this header was preventing the PCHRunner/Runner-Bridging-Header.h
from being generated.In my case I had the phase where the script
/bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build
executes, way at the end, before other critical phases, like source compilation, and this was causing Flutter’s incomplete compilation.I will attach an image of my build phases under correct working conditions. Image: https://www.apkc.net/data/junk/flutter_problem_2021.03.09.png