'Flutter/Flutter.h' file not found in iOS
This comprehensive guide addresses the common but frustrating "Flutter/Flutter.h file not found" error when building Flutter applications for iOS. This error typically occurs when the iOS project structure becomes misconfigured or there are issues with CocoaPods integration.
Problem Overview
The error manifests as a compilation failure with messages like:
'Flutter/Flutter.h' file not found
#import <Flutter/Flutter.h>This indicates that the iOS build system cannot locate the Flutter framework headers, which are essential for native iOS-Flutter communication. The error often affects multiple plugins simultaneously and typically occurs after:
- Switching between Flutter channels
- Updating Flutter or Xcode
- Adding/removing plugins
- Merging code changes that affect the iOS project structure
- Moving projects between different development environments
Primary Solutions
1. Flutter Cache and Dependency Repair
Start with these basic cleanup commands that resolve many common issues:
flutter clean
flutter pub get
flutter pub cache repair
cd ios
pod install --repo-update
cd ..
flutter runTIP
flutter pub cache repair is particularly effective for fixing corrupted package caches that can cause header file issues.
2. Complete iOS Project Regeneration
If the basic cleanup doesn't work, regenerate your iOS project:
- Back up your iOS folder contents (especially
Runner.xcworkspace,Info.plist, assets, and configuration files) - Delete the entire
iosfolder from your project - Run this command from your project root:bash
flutter create . - Restore your backed-up files to the new
iosfolder - Navigate to the
iosdirectory and run:bashpod install - Return to the project root and run your app:bash
flutter run
3. CocoaPods and Xcode Configuration
Podfile Verification
Ensure your Podfile contains the essential post-install hook:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
endPlatform Version Configuration
Update the platform version in your Podfile to match modern iOS requirements:
# Uncomment this line to define a global platform for your project
platform :ios, '13.0' # Or your minimum supported versionBuild Script Order
In Xcode, verify that the Flutter build script is positioned correctly:
- Open your project in Xcode (
ios/Runner.xcworkspace) - Select the Runner target
- Go to Build Phases
- Ensure the "Run Script" phase containing
/bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" buildappears before the "Compile Sources" phase
WARNING
Modifying build phase order manually can resolve issues caused by adding custom scripts (like Crashlytics) that might have been placed incorrectly.
4. Xcode Build Settings
Try these Xcode configuration changes:
- In Xcode, go to Runner → Build Settings
- Search for "Allow Non-modular Includes In Framework Modules"
- Set this value to YES
Alternatively, you can add this configuration to your Podfile:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
end
flutter_additional_ios_build_settings(target)
end
end5. Channel Switching
If you're using the Flutter master channel, consider switching to the stable channel:
flutter channel stable
flutter clean
flutter runINFO
The master channel contains cutting-edge changes that may occasionally break compatibility with plugins. The stable channel is recommended for production development.
Advanced Troubleshooting
Plugin-Specific Solutions
Some plugins (particularly permission_handler, webview_flutter, and Firebase plugins) may require special handling:
Permission Handler Configuration
When using permission_handler, ensure your Podfile modification follows this pattern:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
# Add your permission flags here
# 'PERMISSION_CAMERA=1',
# 'PERMISSION_LOCATION=1',
]
end
end
endFirebase Crashlytics Issues
Older versions of firebase_crashlytics (before 2.0.0) had known issues with this error. Consider updating to the latest version or using a maintained legacy fork if you cannot upgrade.
Architecture Exclusions
For M1 Mac users, adding arm64 to excluded architectures might help:
- In Xcode, select your Runner target
- Go to Build Settings
- Search for "Excluded Architectures"
- Add
arm64for both Debug and Release configurations - Repeat for Pods target
Full Disk Access for Xcode
On macOS, ensure Xcode has Full Disk Access:
- Open System Settings → Privacy & Security → Full Disk Access
- Enable Xcode in the application list
Prevention Strategies
- Maintain consistent Flutter versions across development environments
- Commit Podfile.lock to version control to ensure consistent dependency versions
- Avoid manual modifications to iOS project files when possible
- Regularly update plugins to maintain compatibility
- Use the stable Flutter channel for production development
When All Else Fails
If none of the above solutions work, consider these nuclear options:
- Create a completely new Flutter project and migrate your code
- Check for specific plugin issues on GitHub and consider temporary removal to identify the culprit
- Verify your Xcode installation is complete and updated
DANGER
Before trying radical solutions, ensure you have complete backups of your project and especially the iOS folder contents.
Conclusion
The "Flutter/Flutter.h file not found" error typically stems from iOS project misconfiguration rather than Flutter code issues. By methodically applying these solutions—starting with cache cleaning and dependency updates, then progressing to more invasive fixes—you can usually resolve the problem and return to productive development.