error: 'Flutter/Flutter.h' file not found when flutter run on iOS

84,253

Solution 1

I found a solution!

  1. Backup ios/Runner folder.

  2. Delete the ios folder.

  3. Run flutter create (your project name). in the previous folder where you have your project(cd users/user/"projects_folder") (this will recreate your ios folder).

  4. Paste your Runner backup in the ios folder (into the project).

  5. Open Runner.xcworkspace (into ios folder) and there, check the Version, the Bundle ID, all the info.

  6. (If do you Have Firebase, you have to copy and paste again the Google Service-Info.Plist into the Runner folder (Always through Xcode) (If do you do this manually, it doesn't work).

Finally, flutter run and should work!

If flutter run fails:

  1. cd ios
  2. pod install
  3. cd ..
  4. flutter run

Solution 2

A way easier solution:

  1. Remove ios/Flutter/Flutter.podspec: rm ios/Flutter/Flutter.podspec
  2. flutter clean
  3. Run your app again.

Taken from here

Solution 3

It's happening caused by switching from master/dev back to beta/stable.

Here are two solutions are summarized

This is a bug of flutter and pod install. When flutter does pod install installation dependencies, the synchronization of the framework file in Flutter leads to the loss of the framework file. Once the card owner is lost once, it is only necessary to execute the pod install command. Can install user-specified dependencies, but cannot synchronize framework files in Flutter

Because of ios/Flutter/Flutter.podspec the CocoaPods linking logic was moved into the flutter tool. However, when you switch back to beta/stable, that bogus podspec is still present, but the flutter tool linking logic has been reverted.

1 Solution

The following commands fixed this behavior:

  1. cd ios for going to iOS directory of the flutter app
  2. pod deintegrate
  3. rm Flutter/Flutter.podspec
  4. rm podfile.lock
  5. flutter clean
  6. flutter run

2 Solution

If the above solution does not work then try to switch the channel from Master to stable.

to switch your channel, run this in your terminal:

  1. flutter channel stable

  2. flutter clean

  3. flutter run

Solution 4

This solution worked for me:

Changing PodFile from:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
    config.build_settings['ENABLE_BITCODE'] = 'NO'
    config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
    end
  end
end

to

post_install do |installer|
  installer.pods_project.targets.each do |target| 
    flutter_additional_ios_build_settings(target)
  end
end

Solution 5

Edit: a new version of Crashlytics has just been release for Flutter 2. Just upgrade your pubspec.yml:

firebase_crashlytics: ^2.0.0

Below is my old answear.

For Flutter 2, you can follow the instructions in this GitHub comment. Text pasted below:

Workaround for Flutter 2.0.4 is to use firebase_crashlytics from git instead of pub.dev. This seems to work (ref to the currently latest commit):

  firebase_crashlytics:
    git:
      url: git://github.com/FirebaseExtended/flutterfire.git
      path: packages/firebase_crashlytics/firebase_crashlytics
      ref: 200b8ca8f1c452e4249fb791e53cc55e786ac768
Share:
84,253
Raffaelli L.C.
Author by

Raffaelli L.C.

Updated on February 16, 2022

Comments

  • Raffaelli L.C.
    Raffaelli L.C. about 2 years

    I don't know why but I can't build or run the App in my new Macbook, I run the same folder on another Mac or my windows computer and runs perfectly. here when I run flutter clean, I have to run pub get to solve the issues, Is that normal?

    If I create a new project, I can run flutter run normally, so I think that maybe there I think it may be related to plugins.

    Do you know how can I solve this? Thanks

    Flutter Doctor
    [✓] Flutter (Channel master, 1.24.0-8.0.pre.343, on macOS 11.0.1 20B29 darwin-x64, locale es-419)
        • Flutter version 1.24.0-8.0.pre.343 at /Users/leo/tools/flutter
        • Framework revision cf6c33e58a (2 days ago), 2020-11-21 14:04:01 -0800
        • Engine revision 23a8e027db
        • Dart version 2.12.0 (build 2.12.0-62.0.dev)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
        • Android SDK at /Users/leo/Library/Android/sdk
        • Platform android-30, build-tools 30.0.2
        • 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 12.2)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 12.2, Build version 12B45b
        • CocoaPods version 1.9.3
    
    [✓] 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)
    
    [✓] Connected device (2 available)
        • sdk gphone x86 arm (mobile) • emulator-5554                        • android-x86 • Android 11 (API
          30) (emulator)
        • iPhone 12 Pro Max (mobile)  • F768139D-7B87-4D9E-93B8-14C7D63786B0 • ios         •
          com.apple.CoreSimulator.SimRuntime.iOS-14-2 (simulator)
    
    • No issues found!
    
    
    
    
    Launching lib/main.dart on iPhone 12 Pro Max in debug mode...
    Running Xcode build...                                                  
    Xcode build done.                                           11.4s
    Failed to build iOS app
    Error output from Xcode build:
    ↳
        ** BUILD FAILED **
    
    
    Xcode's output:
    ↳
        <module-includes>:1:9: note: in file included from <module-includes>:1:
        #import "Headers/vibration-umbrella.h"
                ^
        /Users/leo/Apps/previate_esta/ios/Pods/Target Support Files/vibration/vibration-umbrella.h:13:9: note:
        in file included from /Users/leo/Apps/previate_esta/ios/Pods/Target Support
        Files/vibration/vibration-umbrella.h:13:
        #import "VibrationPlugin.h"
                ^
        /Users/leo/.pub-cache/hosted/pub.dartlang.org/vibration-1.4.0/ios/Classes/VibrationPlugin.h:1:9: error:
        'Flutter/Flutter.h' file not found
        #import <Flutter/Flutter.h>
                ^
        <unknown>:0: error: could not build Objective-C module 'vibration'
        In file included from
        /Users/leo/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.3/ios/Classes/FLTURLLauncherPlugin.m:7:
        /Users/leo/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.3/ios/Classes/FLTURLLauncherPlugin.h:5:9
        : fatal error: 'Flutter/Flutter.h' file not found
        #import <Flutter/Flutter.h>
                ^~~~~~~~~~~~~~~~~~~
        1 error generated.
        In file included from
        /Users/leo/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.10/ios/Classes/FLTSharedPreference
        sPlugin.m:5:
        /Users/leo/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.10/ios/Classes/FLTSharedPreference
        sPlugin.h:5:9: fatal error: 'Flutter/Flutter.h' file not found
        #import <Flutter/Flutter.h>
                ^~~~~~~~~~~~~~~~~~~
        1 error generated.
        In file included from
        /Users/leo/.pub-cache/hosted/pub.dartlang.org/share-0.6.5/ios/Classes/FLTSharePlugin.m:5:
        /Users/leo/.pub-cache/hosted/pub.dartlang.org/share-0.6.5/ios/Classes/FLTSharePlugin.h:5:9: fatal
        error: 'Flutter/Flutter.h' file not found
        #import <Flutter/Flutter.h>
                ^~~~~~~~~~~~~~~~~~~
        1 error generated.
        In file included from
        /Users/leo/.pub-cache/hosted/pub.dartlang.org/sensors-0.4.2+4/ios/Classes/FLTSensorsPlugin.m:5:
        /Users/leo/.pub-cache/hosted/pub.dartlang.org/sensors-0.4.2+4/ios/Classes/FLTSensorsPlugin.h:5: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 12 Pro Max.
    
  • Raffaelli L.C.
    Raffaelli L.C. over 3 years
    I edit the answer, I hope it helps you. If you have any questions, ask me!
  • Cliff Helsel
    Cliff Helsel over 3 years
    Didn't work for me: fatal error: 'Flutter/Flutter.h' file not found. Running on channel master with build flavors.
  • Michele Volpato
    Michele Volpato over 3 years
    I tried this, but deleting only ios/Flutter and not the entire ios folder, and it worked. Make a backup of it first!
  • Viren V Varasadiya
    Viren V Varasadiya about 3 years
    This is only solution work for me, Thank you!
  • Jason Waku
    Jason Waku about 3 years
    I tried this with "rm podfile.lock" after 1st step. and clean the cache in android studio , restored it. so the error is gone in my case. thanks. it was a good shortcut.
  • zackygaurav
    zackygaurav about 3 years
    flutter.h error is now gone with this solution. It works. Any reason? I am an Android Developer so I don't have a clue what is happening under the hood in iOS.
  • Vit Veres
    Vit Veres about 3 years
    Same for me. The easiest temporary solution is to use the version of library from git. ` firebase_crashlytics: git: url: git://github.com/FirebaseExtended/flutterfire.git path: packages/firebase_crashlytics/firebase_crashlytics `
  • Mol0ko
    Mol0ko about 3 years
    they already released firebase_crashlytics v2.0.0, bug fixed
  • p0wl
    p0wl about 3 years
    I'm sorry, I don't really know anything about pod files. But it seems that there is a new method that handles this case smoothly. Correct me, if I'm wrong :)
  • Jayson O.
    Jayson O. about 3 years
    Works like a charm. Thanks!
  • kyu
    kyu about 3 years
    From what I understood flutter_additional_ios_build_settings(target) is automatically added from Flutter 2.0. I created my project in Flutter version 1.0 which didn't contain this line in the PodFile. That was my problem.
  • Zenko
    Zenko about 3 years
    Since the edit queue is full. If you have created a splash screen don't forget to overwrite the Assets.xcassets folder and Main.storyboard and LaunchScreen.storyboard. (IMPORTANT: You MUST manually drag and drop to Xcode, not simply overwrite it in Finder.) Moreover, copy the content of info.plist.
  • edn
    edn about 3 years
    @Raffaelli L.C., you are a legend. I tried EVERYTHING but this one the only one that worked. Thank you for sharing.
  • Gorges
    Gorges about 3 years
    I also had to upgrade platform :ios, '10.0' in ios/Podfile
  • Adnan Kazi
    Adnan Kazi almost 3 years
    In my case, I had a large number of old dependencies so I cant manually change it, but your other solution worked like a charm I have downgraded the flutter version to 2.0.3 and it worked thanks 👍
  • Andy A.
    Andy A. almost 3 years
    @MostafaAEl-Hakak Please specify what you mean, your answere is hard to understand for me.
  • Karthik Kannan
    Karthik Kannan almost 3 years
    Hi @RaffaelliL.C. I have a question, where do you paste your backup iOS project? When I ran flutter create foo_bar it created a totally new flutter project for me called foo_bar inside my already existing project. This new project had an ios/ folder so it's a bit confusing as to where to paste my new folder. Thanks!
  • Amit Khetan
    Amit Khetan almost 3 years
    I suggest don't do it like this. @PareshMangukiya answered the right way.
  • Ameer
    Ameer almost 3 years
    This solution worked for me with Flutter Channel stable, 2.2.1. The only additional thing I did is Pub get + Pub Upgrade after making shared changes. Thanks @Michał Dobi Dobrzański
  • genericUser
    genericUser almost 3 years
    I have added today firebase_crachlytics version 0.4.0 and faced the same problem. Updating the version solved the issue. Thanks!
  • Marvioso
    Marvioso almost 3 years
    You are an absolute life saver!
  • Harsh Phoujdar
    Harsh Phoujdar almost 3 years
    Flutter create is not working for me "testProject" is not a valid Dart package name. See dart.dev/tools/pub/pubspec#name for more information. I think what might have happened here, is previous version of Flutter would have allowed a camel cased project name, while the current one does not. How to come out of this mess?
  • Fellow7000
    Fellow7000 almost 3 years
    I had only this config.build_settings['ENABLE_BITCODE'] = 'NO', so I removed it and the build worked out. thanks
  • Abbas
    Abbas over 2 years
    Or you can simply delete the ios directory and do "flutter create ." ios inside your project directory, to create a fresh new ios directory. Make sure to backup any code that you did manually inside the ios file.
  • Cosmo Dai
    Cosmo Dai over 2 years
    Maybe missing this line: flutter_additional_ios_build_settings(target)
  • Aziz
    Aziz over 2 years
    It worked for me but deleting the entire ios folder and creating a new fresh one, then you can apply your edits after it.
  • Eray Hamurlu
    Eray Hamurlu over 2 years
    I didn't paste backup ios folder and work fine with new created ios folder.
  • rbatty19
    rbatty19 over 2 years
    really good advice ( solved on M1 mac ), thank you
  • Kamil OZTURK
    Kamil OZTURK over 2 years
    I got this error beacuse of webview_flutter but these steps didnt work for me. i think reason of this error releted the podfile configuration. it can be related about "use_frameworks!" or platform ios declaration or else. Im not sure.
  • Beyond Chao
    Beyond Chao over 2 years
    Thanks! Worked for me! It's happening caused by switching flutter version from to 2.2.1 to 1.22.2
  • Astik Anand
    Astik Anand over 2 years
    Thanks a lot for this answer @RaffaelliL.C.
  • LearningPath
    LearningPath about 2 years
    After following these steps, i have still this issue...any other clues?
  • Leena Marie
    Leena Marie about 2 years
    Saved my life!!
  • Almett
    Almett about 2 years
    Solution 1 helped me. Copying the Runner file before removing the ios folder and paste back again after is the only extra step I took compared to the solution of @Paresh Mangukiya below.
  • Ian Wambai
    Ian Wambai about 2 years
    There has to be a better solution than this, I have made too many custom changes to my iOS project and deleting the entire thing is not an option for me.
  • ZeroCode
    ZeroCode about 2 years
    Didn't fix the issue for me on m1 chip.
  • ZXERSTON
    ZXERSTON almost 2 years
    I am facing an issue after running flutter create . It says "PROJECT NAME" is not a valid Dart package name. See dart.dev/tools/pub/pubspec#name for more information"
  • ZXERSTON
    ZXERSTON almost 2 years
    I am facing an issue after running flutter create . It says "PROJECT NAME" is not a valid Dart package name. See dart.dev/tools/pub/pubspec#name for more information
  • Mr. Ripper
    Mr. Ripper almost 2 years
    @ ZXERSTON Please ensure to run 'flutter create .' while in the root directory, (including the space and period. If you're not sure how to get to the root directory, run 'cd ..' in the terminal including the space and 2 periods
  • Tsimbalyuk Konstantin
    Tsimbalyuk Konstantin almost 2 years
    You save my day!!! 🙏 you!!!
  • Ujjawal Maurya
    Ujjawal Maurya almost 2 years
    It's not a SDK related problem