Flutter fatal error: ‘Flutter/Flutter.h’ file not found

Last updated on July 11, 2022 Guest Contributor Loading... 24 comments

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 couple of different solutions to fix a common bug you may run into when developing iOS apps with Flutter.

The Problem

After upgrading Flutter from version 1.x to version 2.x and later 3.x, I faced one fatal error when running my project on an iOS simulator (this project was created months ago and ran well in the past).

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 panic, the solutions below work for me, and they will work for you as well.

Solutions

Solution 1

This method has the best chance of success, and we still have other alternate plans in the back if it doesn’t work for you.

1. Back up 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 backed up 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 to 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, and choosing Add Files to “Runner” from the drop-down menu, then select the GoogleService-Info.plist file that is associated with your project.

6. Navigate to your ios folder and run:

pod install

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:

flutter clean 

And update dependencies in .pub-cache:

flutter pub cache repair

Then run your project again.

Solution 2

Occasionally, the error is caused by a simple reason: you are currently on the Master channel instead of the Stable channel. According to the Flutter wiki:

  • Master channel: The current tip-of-tree, absolute latest cutting-edge build. Usually functional, though sometimes things accidentally break.
  • Stable channel: This channel is strongly recommended to use for all production app releases.

What you need to do now is to switch to the stable channel:

flutter channel stable

Then:

flutter clean

Finally:

flutter run

Solution 3

This solution was contributed by a guest. I haven’t tested it myself, but he said it worked well for him. You could try it if the two approaches above didn’t solve the problem.

1. Go to <your-project>/ios folder and delete the following:

  • Flutter/Flutter.podspec file
  • Pods folder
  • Podfile.lock file

2. Still in the ios folder, execute the following command:

pod install --repo-update

3. Navigate to the root directory of your project and clean your project by running this command:

flutter clean

4. Run it:

flutter run

Final Words

Hope one of the solutions above works for you. Have a nice day and happy Fluttering. Further reading:

You can also take a tour around our Flutter topic page or Dart topic page for the latest tutorials and examples.

Subscribe
Notify of
guest
24 Comments
Inline Feedbacks
View all comments
dirkk
dirkk
4 months ago

you can use this command to find this issue https://docs.flutter.dev/development/add-to-app/ios/project-setup.
it’s worked for me.

flutter build ios-framework --output=some/path/MyApp/Flutter/

use

pwd

command to get the current directory

replace –output=some/path/MyApp/Flutter/ by –output=currentdirectory/directoryapp/ios/Flutter

so

flutter build ios-framework --output=currentdirectory/directoryapp/ios/Flutter

for me it was:

flutter build ios-framework --output=/Users/ilimigroup/StudioProjects/Telia-ios/telia/ios/Flutter

after that, you can run in xcode

Kururu95
Kururu95
6 months ago

spend more than three days trying solve this:)

Ammar
Ammar
1 year ago

This worked for me THAAANKS

A Goodman
Admin
A Goodman
1 year ago
Reply to  Ammar

😁

Arpan Aggarwal
Arpan Aggarwal
1 year ago

These steps did not work for me. My observation from other projects is Flutter.framework is missing from ios folder.

Any guess what could be potential reason.

A Goodman
Admin
A Goodman
1 year ago
Reply to  Arpan Aggarwal

Hey Arpan, can you post your error messages here? Are you sure that you got the same error?

Arpan Aggarwal
Arpan Aggarwal
1 year ago
Reply to  A Goodman

Appreciate your quick reply.

The error is same
ios/Runner/GeneratedPluginRegistrant.h:8:9: ‘Flutter/Flutter.h’ file not found

This only comes when trying to make in xcode or vscode.

On command line it works fine.

Not sure, if its connected with this issue.
https://github.com/flutter/flutter/issues/73845

A Goodman
Admin
A Goodman
1 year ago
Reply to  Arpan Aggarwal

Thanks for your information. I will recheck the solutions and update the post as needed.

swati
swati
1 year ago

If we dont copy podfile then how would pod install work… it says no pod file… even lib is new so its also not working after runing pub get

A Goodman
Admin
A Goodman
1 year ago
Reply to  swati

The ios folder and the profile will be generated when you run “flutter create .”. Once you follow the instruction, it will work.

Zill
Zill
1 year ago

Nice. It worked!

Harry
Harry
1 year ago

Thanks bro, after hours and multiple tries, yours is the only one that worked!

Rahul raj
Rahul raj
1 year ago

Thanks..its working

Phil
Phil
1 year ago

Got stuck on flutter create . since my package has a period in it xxxxxx.xxxxxx. any advice/. Thx

Nikhil
Nikhil
1 year ago

Thanks a lot bro , worked perfectly

A Goodman
Admin
A Goodman
1 year ago
Reply to  Nikhil

I’m so glad to hear that

Sumeda
Sumeda
1 year ago

Thanks a lot.
This works for me.

Vignesh Marimuthu
Vignesh Marimuthu
1 year ago

You saved my day bro. Got stuck with this for the past 2 days. Thank you for this article.

A Goodman
Admin
A Goodman
1 year ago

I’m really happy to hear it. Have a nice day bro 🙂

Mike
Mike
1 year ago

I have 3 projects that get this error. This guide works for 2 projects. I’ll try it again.

madan raj
madan raj
1 year ago

you saved my day
thanks

Wilyanto
Wilyanto
1 year ago

Totally works for me, Thank You!

A Goodman
Admin
A Goodman
1 year ago
Reply to  Wilyanto

I’m really glad to hear so 🙂

Egidio
Egidio
1 year ago

any advice?

Related Articles