Repository navigation
<Flutter/Flutter.h> cannot be imported when a pod transitive depends on Flutter #126251
Copy link
Copy link
Closed
Closed
Copy link
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listfound in release: 3.11Found to occur in 3.11Found to occur in 3.11found in release: 3.7Found to occur in 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-iosOwned by iOS platform teamOwned by iOS platform teamtriaged-iosTriaged by iOS platform teamTriaged by iOS platform team
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Steps to reproduce
run the project in bug_demo directory.
Expected results
Build Success.
Actual results
Build Failed.
Code sample
https://github.com/intspt/bug_demo
Screenshots or Video
Logs
Logs
In file included from /Users/spt/Developer/bug_demo/bug_demo/ios/NativePod/Classes/test.m:1:
/Users/spt/Developer/bug_demo/bug_demo/ios/NativePod/Classes/test.h:1:9: fatal error: 'Flutter/Flutter.h' file not found
#import <Flutter/Flutter.h>
^~~~~~~~~~~~~~~~~~~
1 error generated.Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.7.12, on macOS 13.3.1 22E261 darwin-x64, locale zh-Hans-CN)
• Flutter version 3.7.12 on channel stable at /Users/spt/.flutterHomeOfficial3.0
• Upstream repository [email protected]:flutter/flutter.git
• Framework revision 4d9e56e694 (3 weeks ago), 2023-04-17 21:47:46 -0400
• Engine revision 1a65d409c7
• Dart version 2.19.6
• DevTools version 2.20.1
• Pub download mirror https://pub.flutter-io.cn
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
• Android SDK at /Users/spt/Library/Android/sdk
• Platform android-32, build-tools 32.0.0
• ANDROID_SDK_ROOT = /Users/spt/Library/Android/sdk
• Java binary at: /Users/spt/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9862592/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14E222b
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.2)
• Android Studio at /Users/spt/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9862592/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 17.0.6+0-17.0.6b802.4-9586694)
[✓] VS Code (version 1.77.3)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.62.0
[✓] Connected device (5 available)
• M2012K11AC (mobile) • 3514df5f • android-arm64 • Android 13 (API 33)
• iPhone (mobile) • 00008020-000954E136A1002E • ios • iOS 16.4.1 20E252
• iPhone 14 Pro Max (mobile) • C247BDBA-F6F2-4DF3-8E25-A511C760D87D • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
• macOS (desktop) • macos • darwin-x64 • macOS 13.3.1 22E261 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 112.0.5615.137
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listfound in release: 3.11Found to occur in 3.11Found to occur in 3.11found in release: 3.7Found to occur in 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-iosOwned by iOS platform teamOwned by iOS platform teamtriaged-iosTriaged by iOS platform teamTriaged by iOS platform team

Activity
intspt commentedon May 8, 2023
In the normal_demo, cocoapods added the directory of Flutter.framework to the FRAMEWORK_SEARCH_PATHS of NativePod. Because shared_preferences dependencies will be inherited to NativePod.

But in the bug_demo, Flutter is a fake pod. FRAMEWORK_SEARCH_PATHS is processed by podhelper, which misses the scenarios of transitive dependencies, so an error will be reported during compilation.

darshankawar commentedon May 8, 2023
@intspt
I cloned the repo and tried to run but it gave me below errors:
intspt commentedon May 9, 2023
I'm sorry that I didn't encounter this error, but I have modified it according to the prompts, you can try again.
darshankawar commentedon May 9, 2023
Thanks for the update. Now I was able to replicate the error as below, but I am not sure if this is a bug or intended so will keep it open for team's input on expected behavior.
stable, master flutter doctor -v
intspt commentedon May 9, 2023
In the normal_demo, cocoapods added the directory of Flutter.framework to the FRAMEWORK_SEARCH_PATHS of NativePod. Because shared_preferences dependencies will be inherited to NativePod.

But in the bug_demo, Flutter is a fake pod. FRAMEWORK_SEARCH_PATHS is processed by podhelper, which misses the scenarios of transitive dependencies, so an error will be reported during compilation.

In fact, if a pod transitive depends on a pod containing a framework, cocoapods will add the path of the framework to its FRAMEWORK_SEARCH_PATHS.
So I modified the relevant logic in podhelper, hoping to be consistent with the behavior of cocoapods.
stuartmorgan-g commentedon May 14, 2023
And what are the conceptual steps to get to the state you've created in bug_demo? I've read the comments in the PR several times and I'm still not clear on what exactly you are doing, and what the use case is.
hyiso commentedon May 17, 2023
Similar problem.
Upgrade Flutter SDK from '2.10' to 3.10, a third Pod depends on a Flutter plugin pod while throw compiling error: 'Flutter/Flutter.h' not found.
After steps:
next unless target.dependencies.any? { |dependency| dependency.name == 'Flutter' }in rootpodhelper.rbfilepod installagain in iOS host project.Then Build/Run host App succeeded.
hyiso commentedon May 17, 2023
IMO, the PR is trying to change the condition for finding pods depending on 'Flutter' directly to be suitable for pods depending on 'Flutter' transitively.
That is, for example:
Plugin A -> Flutter
Pod B -> Plugin A
Before, post_install settings only affects 'Plugin A'
After, post_install settings also affects 'Pod B'
stuartmorgan-g commentedon May 17, 2023
This is the part I'm still not clear on: what is the use case for this? Flutter plugins are not "real" Pods intended to be published for use as such, that's just a mechanism for integrating them into Flutter application builds.
hyiso commentedon May 17, 2023
For Add-to-app,
flutter build ios-frameworkgenerates.xcframeworks for each Flutter plugin.As Flutter dev is only a small part of App dev, Flutter developers usually bundle these
.xcframeworks of each Flutter plugin to a standard pod and publish it to internal pod repository.When integrating to host iOS project, the published Flutter plugin pods are used so that other iOS developers don't have to install Flutter SDK.
Based on this, some business pod will depends on Flutter plugin pod, and thus depends on 'Flutter' transitively.
stuartmorgan-g commentedon May 17, 2023
So are you also internally publishing your own copy of the
Flutterpod as well?hyiso commentedon May 17, 2023
Yes, all these pods are used only in
Releasemode.in
Debugmode, the Flutter SDK and Flutter plugin source are used(for Flutter developers)intspt commentedon May 18, 2023
The purpose of this change is not to solve this bug (although this change can indeed solve this bug). The real purpose is that Flutter currently forges a pod named Flutter, but this fake pod is still inconsistent with the real pod in some scenarios (such as the bug scenario).
All in all, the core goal of the change is to make the fake Flutter pod behave the same as the real Flutter pod.
PS:
As said in this comment,
flutter/packages/flutter_tools/bin/podhelper.rb
Line 210 in f31dae2
jmagman commentedon Jan 3, 2024
Sorry for the long delay getting back to this. I was on an extended leave. I understand the problem now, thanks for the detailed demo apps.
I can change your
bug_demopodspec to:spec.dependency 'shared_preferences' + spec.dependency 'Flutter'And the Flutter import works fine because you told CocoaPods you want to import and link on Flutter. Which is more correct because interestingly, in
normal_demoCocoaPods is adding the transitive dependency to the search path:But it's not adding
-framework "Flutter"toOTHER_LDFLAGS.So I guess it's assuming
CLANG_MODULES_AUTOLINKis always set to YES (probably a safe assumption). When I set that toNOin your normal_demo and try to use aFluttersymbol, it fails as expected:That being said, your solution seems fine to make Flutter tooling closer to CocoaPods's kind of strange assumption about transitive dependencies. Which isn't an overarching goal for Flutter tooling, but if it saves you some trouble then it seems harmless?
By the way is it a custom build of Flutter? If not, can you use Option C and not publish your own internal version of Flutter.xcframework.
Solve the problem that <Flutter/Flutter.h> cannot be imported when a …
github-actions commentedon Jan 31, 2024
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.