Skip to content

<Flutter/Flutter.h> cannot be imported when a pod transitive depends on Flutter #126251

Closed

Description

@intspt

Is there an existing issue for this?

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

Screenshots / Video demonstration

image

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!

Activity

  1. intspt commented on May 8, 2023

    @intspt
    ContributorAuthor

    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.
    image

    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.
    image

  2. darshankawar commented on May 8, 2023

    @darshankawar
    Member

    @intspt
    I cloned the repo and tried to run but it gave me below errors:

        Fetching external sources
        -> Fetching podspec for `Flutter` from `Flutter`
        -> Fetching podspec for `NativePod` from `NativePod`
        [!] The `NativePod` pod failed to validate due to 2 errors:
            - ERROR | license: Sample license type.
            - WARN  | homepage: The homepage has not been updated from default
            - WARN  | github_sources: Github repositories should use an `https`
            link.
            - WARN  | summary: The summary is not meaningful.
            - ERROR | description: The description is empty.
    
    
    
  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on May 8, 2023
  4. intspt commented on May 9, 2023

    @intspt
    ContributorAuthor

    @intspt I cloned the repo and tried to run but it gave me below errors:

        Fetching external sources
        -> Fetching podspec for `Flutter` from `Flutter`
        -> Fetching podspec for `NativePod` from `NativePod`
        [!] The `NativePod` pod failed to validate due to 2 errors:
            - ERROR | license: Sample license type.
            - WARN  | homepage: The homepage has not been updated from default
            - WARN  | github_sources: Github repositories should use an `https`
            link.
            - WARN  | summary: The summary is not meaningful.
            - ERROR | description: The description is empty.
    

    I'm sorry that I didn't encounter this error, but I have modified it according to the prompts, you can try again.

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on May 9, 2023
  6. darshankawar commented on May 9, 2023

    @darshankawar
    Member

    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.

    Changed 11 dependencies!
    Launching lib/main.dart on iPhone 13 in debug mode...
    Running pod install...                                           1,356ms
    Running Xcode build...                                                  
    Xcode build done.                                            9.1s
    Failed to build iOS app
    Lexical or Preprocessor Issue (Xcode): 'Flutter/Flutter.h' file not found
    /Users/dhs/Documents/NCFlutter/bug_demo/bug_demo/ios/NativePod/Classes/test.h:0:
    8
    
    
    Could not build the application for the simulator.
    Error launching application on iPhone 13.
    dhs@Dhss-MacBook-Pro bug_demo % 
    
    stable, master flutter doctor -v
    [!] Flutter (Channel stable, 3.7.12, on macOS 12.2.1 21D62 darwin-x64, locale
        en-GB)
        • Flutter version 3.7.12 on channel stable at
          /Users/dhs/documents/fluttersdk/flutter
        ! Warning: `flutter` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
          your current Flutter SDK checkout at
          /Users/dhs/documents/fluttersdk/flutter. Consider adding
          /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
        ! Warning: `dart` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
          Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
          of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 4d9e56e694 (3 days ago), 2023-04-17 21:47:46 -0400
        • Engine revision 1a65d409c7
        • Dart version 2.19.6
        • DevTools version 2.20.1
        • If those were intentional, you can disregard the above warnings; however
          it is recommended to use "git" directly to perform update checks and
          upgrades.
    
    [!] Xcode - develop for iOS and macOS (Xcode 12.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! Flutter recommends a minimum Xcode version of 13.
          Download the latest version or update via the Mac App Store.
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.21.0
    
    [✓] Connected device (5 available)
        • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
        • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
          ios            • iOS 14.4.1 18D61
        • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
          ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
        • macOS (desktop)            • macos                                    •
          darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
        • Chrome (web)               • chrome                                   •
          web-javascript • Google Chrome 98.0.4758.80
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    [!] Flutter (Channel master, 3.11.0-2.0.pre.73, on macOS 12.2.1 21D62
        darwin-x64, locale en-GB)
        • Flutter version 3.11.0-2.0.pre.73 on channel master at
          /Users/dhs/documents/fluttersdk/flutter
        ! Warning: `flutter` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
          your current Flutter SDK checkout at
          /Users/dhs/documents/fluttersdk/flutter. Consider adding
          /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
        ! Warning: `dart` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
          Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
          of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 8c5a1ea728 (8 hours ago), 2023-05-08 14:00:20 -0700
        • Engine revision 8d3a8162b3
        • Dart version 3.1.0 (build 3.1.0-86.0.dev)
        • DevTools version 2.23.1
        • If those were intentional, you can disregard the above warnings; however
          it is recommended to use "git" directly to perform update checks and
          upgrades.
    
    [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at /Users/dhs/Library/Android/sdk
        ✗ cmdline-tools component is missing
          Run `path/to/sdkmanager --install "cmdline-tools;latest"`
          See https://developer.android.com/studio/command-line for more details.
        ✗ Android license status unknown.
          Run `flutter doctor --android-licenses` to accept the SDK licenses.
          See https://flutter.dev/docs/get-started/install/macos#android-setup for
          more details.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 13C100
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2021.3.2)
        • IntelliJ at /Applications/IntelliJ IDEA.app
        • Flutter plugin version 65.1.4
        • Dart plugin version 213.7228
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.29.0
    
    [✓] Connected device (3 available)
        • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios
          • iOS 15.3.1 19D52
        • macOS (desktop)           • macos                                    •
          darwin-x64     • macOS 12.2.1 21D62 darwin-x64
        • Chrome (web)              • chrome                                   •
          web-javascript • Google Chrome 109.0.5414.119
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
          
    [!] Xcode - develop for iOS and macOS (Xcode 12.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! Flutter recommends a minimum Xcode version of 13.
          Download the latest version or update via the Mac App Store.
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.21.0
    
    [✓] Connected device (5 available)
        • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
        • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
          ios            • iOS 14.4.1 18D61
        • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
          ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
        • macOS (desktop)            • macos                                    •
          darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
        • Chrome (web)               • chrome                                   •
          web-javascript • Google Chrome 98.0.4758.80
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    
    
    
  7. added
    platform-iosiOS applications specifically
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on May 9, 2023
  8. intspt commented on May 9, 2023

    @intspt
    ContributorAuthor

    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.

    Changed 11 dependencies!
    Launching lib/main.dart on iPhone 13 in debug mode...
    Running pod install...                                           1,356ms
    Running Xcode build...                                                  
    Xcode build done.                                            9.1s
    Failed to build iOS app
    Lexical or Preprocessor Issue (Xcode): 'Flutter/Flutter.h' file not found
    /Users/dhs/Documents/NCFlutter/bug_demo/bug_demo/ios/NativePod/Classes/test.h:0:
    8
    
    
    Could not build the application for the simulator.
    Error launching application on iPhone 13.
    dhs@Dhss-MacBook-Pro bug_demo % 
    

    stable, master flutter doctor -v

    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.
    image

    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.
    image

    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.

  9. stuartmorgan-g commented on May 14, 2023

    @stuartmorgan-g
    Contributor

    Steps to reproduce

    run the project in bug_demo directory.

    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.

  10. hyiso commented on May 17, 2023

    @hyiso
    Contributor

    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:

    1. commenting out next unless target.dependencies.any? { |dependency| dependency.name == 'Flutter' } in root podhelper.rb file
    2. pod install again in iOS host project.

    Then Build/Run host App succeeded.

  11. hyiso commented on May 17, 2023

    @hyiso
    Contributor

    Steps to reproduce

    run the project in bug_demo directory.

    And what are the conceptual steps to get to the state you've cerated 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.

    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'

  12. stuartmorgan-g commented on May 17, 2023

    @stuartmorgan-g
    Contributor

    Pod B -> Plugin A

    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.

  13. hyiso commented on May 17, 2023

    @hyiso
    Contributor

    Pod B -> Plugin A

    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.

    For Add-to-app, flutter build ios-framework generates .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.

  14. stuartmorgan-g commented on May 17, 2023

    @stuartmorgan-g
    Contributor

    so that other iOS developers don't have to install Flutter SDK.

    So are you also internally publishing your own copy of the Flutter pod as well?

  15. hyiso commented on May 17, 2023

    @hyiso
    Contributor

    so that other iOS developers don't have to install Flutter SDK.

    So are you also internally publishing your own copy of the Flutter pod as well?

    Yes, all these pods are used only in Release mode.

    in Debug mode, the Flutter SDK and Flutter plugin source are used(for Flutter developers)

  16. intspt commented on May 18, 2023

    @intspt
    ContributorAuthor

    Steps to reproduce

    run the project in bug_demo directory.

    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.

    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,

    # Framework linking is handled by Flutter tooling, not CocoaPods.
    , after vendored_frameworks is replaced by path/to/nothing, the relevant Compilation settings are handled by podhelper. But the processing result is not consistent with the value of vendored_frameworks when Flutter.xcframework. So this change is necessary.

  17. added
    P2Important issues not at the top of the work list
    on Jul 31, 2023
  18. jmagman commented on Jan 3, 2024

    @jmagman
    Member

    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_demo podspec 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_demo CocoaPods is adding the transitive dependency to the search path:

    FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/shared_preferences" "${PODS_ROOT}/../Flutter" "${PODS_XCFRAMEWORKS_BUILD_DIR}/Flutter"
    

    But it's not adding -framework "Flutter" to OTHER_LDFLAGS.

    OTHER_LDFLAGS = $(inherited) -framework "shared_preferences"
    

    So I guess it's assuming CLANG_MODULES_AUTOLINK is always set to YES (probably a safe assumption). When I set that to NO in your normal_demo and try to use a Flutter symbol, it fails as expected:

    ld: Undefined symbols:
      _OBJC_CLASS_$_FlutterError, referenced from:
           in test.o
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    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?

    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.

    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.

  19. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jan 17, 2024
  20. github-actions commented on Jan 31, 2024

    @github-actions

    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 -v and a minimal reproduction of the issue.

  21. locked as resolved and limited conversation to collaborators on Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listfound in release: 3.11Found to occur in 3.11found in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions