Flutter fatal error: ‘Flutter/Flutter.h’ file not found
( 254 Articles)
Flutter is an open-source UI software development kit that grows very quickly and is regularly updated with major changes. Therefore, it is very normal for you to get incompatible errors when working with it.
This short post shows you a solution to fix a common bug you may run into when developing iOS apps with Flutter.
After upgrading Flutter from version 1.x to version 2.x, I faced one fatal error when running my project on an iOS simulator (this project was created a few months ago).
The error message:
fatal error: 'Flutter/Flutter.h' file not found
Also with this project but the day before, it ran completely fine.
The full output:
Xcode's output: ↳ 1 error generated. In file included from /Users/goodman/Coding/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.27/ios/Classes/FLTPathProviderPlugin.m:5: /Users/goodman/Coding/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.27/ios/Classes/FLTPathProviderPlugin.h:5:9: fatal error: 'Flutter/Flutter.h' file not found #import <Flutter/Flutter.h> ^~~~~~~~~~~~~~~~~~~ 1 error generated. In file included from /Users/goodman/Coding/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_app_badger-1.1.2/ios/Classes/FlutterAppBadgerPlugin.m:1: /Users/goodman/Coding/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_app_badger-1.1.2/ios/Classes/FlutterAppBadgerPlugin.h:1:9: fatal error: 'Flutter/Flutter.h' file not found #import <Flutter/Flutter.h> ^~~~~~~~~~~~~~~~~~~ 1 error generated. 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 11.
You can see error messages with the names of plugins that are different from mine (like shared_preferences, sqflite, firebase family packages, etc), but it will all be related to the Flutter.h file. Don’t be panic, the solution below works for me and it will work for you as well.
1. Backup the Runner folder in your ios folder to a safe place.
2. Delete the ios folder:
3. Still in the root directory, run the following command:
flutter create .
A new ios folder will be generated inside your project.
4. Copy and paste the Runner folder you have backup before to the new ios folder:
A dialog will appear. Click on the Replace button to continue.
5. If your project is NOT using Firebase, you can ignore this step and move on the next one. Otherwise, you need to re-add the GoogleService-Info.plist file by opening the ios folder with Xcode, right-click on Runner, choose Add Files to “Runner” from the drop-down menu, then select the GoogleService-Info.plist file that associated with your project.
6. Navigate to your ios folder and run:
You may fall into something like this:
[!] CocoaPods could not find compatible versions for pod "firebase_analytics": In Podfile: firebase_analytics (from `.symlinks/plugins/firebase_analytics/ios`) Specs satisfying the `firebase_analytics (from `.symlinks/plugins/firebase_analytics/ios`)` dependency were found, but they required a higher minimum deployment target. [!] Automatically assigning platform `iOS` with version `9.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
This error can happen with other packages, not just firebase_analytics as mine. Don’t worry. Just open your Podfile, uncomment the platform :ios line and replace 9.0 with a higher version (version 11.0 is pretty good to go):
# Uncomment this line to define a global platform for your project platform :ios, '11.0'
Now run pod install again and it should work (a few warnings may appear but we don’t care about them).
7. Finally, go back to your root directory and run your project as normal (don’t forget to launch an iOS simulator first):
cd .. flutter run
If you still get errors, clear the Flutter’s build cache by executing this:
Then run your project again.
Hope this helps. Have a nice day and happy Fluttering. Further reading:
- Flutter error: CocoaPods’s specs repository is too out-of-date
- Flutter and Firestore Database: CRUD example
- Flutter error: No Firebase App ‘[DEFAULT]’ has been created
- Flutter: Configure Firebase for iOS and Android
- Flutter: Correctly adding GoogleServices-Info.plist to iOS