【问题标题】:Flutter.h not found errorFlutter.h 未找到错误
【发布时间】:2018-11-13 05:46:06
【问题描述】:

几天前我已经失去了为 iOS 构建 Flutter 应用程序的能力。我将我的 iPad 更新到 11.4,这迫使我将 xCode 更新到 9.4,而且我认为 Flutter 也有一个新版本。在我无限的智慧中,我更新了它们,现在无法再测试我的项目了。

随着最后期限的临近,我正在寻找有关如何再次行动的建议。我对 Apple 产品不太熟悉,所以还不太了解 xCode 等。

这是一个全新的“FLUTTER CREATE testproject”项目,没有对其进行任何更改。

FLUTTER RUN 日志:

Launching lib/main.dart on iPad Pro (12.9-inch) (2nd generation) in debug mode...
Starting Xcode build...
Xcode build done.
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **

Xcode's output:
↳
    === BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Debug ===
    cp: /Users/trevburley/FlutterSDK/flutter/bin/cache/artifacts/engine/ios/Flutter.framework: No such file or directory
    find: /Users/trevburley/IdeaProjects/testproject/ios/Flutter/Flutter.framework: No such file or directory
    Project /Users/trevburley/IdeaProjects/testproject built and packaged successfully.
    Command /bin/sh emitted errors but did not return a nonzero exit code to indicate failure
    In file included from /Users/trevburley/IdeaProjects/testproject/ios/Runner/GeneratedPluginRegistrant.m:5:
    /Users/trevburley/IdeaProjects/testproject/ios/Runner/GeneratedPluginRegistrant.h:8:9: fatal error: 'Flutter/Flutter.h' file not found
    #import <Flutter/Flutter.h>
            ^~~~~~~~~~~~~~~~~~~
    1 error generated.
Could not build the application for the simulator.
Error launching application on iPad Pro (12.9-inch) (2nd generation).

详细的 FLUTTER DOCTOR:

Trevs-MBP:testproject trevburley$ flutter doctor -v
[✓] Flutter (Channel beta, v0.4.4, on Mac OS X 10.13.5 17F77, locale en-GB)
    • Flutter version 0.4.4 at /Users/trevburley/FlutterSDK/flutter
    • Framework revision f9bb4289e9 (3 weeks ago), 2018-05-11 21:44:54 -0700
    • Engine revision 06afdfe54e
    • Dart version 2.0.0-dev.54.0.flutter-46ab040e58

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at /Users/trevburley/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.4, Build version 9F1027a
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 25.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[✓] IntelliJ IDEA Community Edition (version 2018.1.4)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 25.0.2
    • Dart plugin version 181.4892.1

[✓] VS Code (version 1.23.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Dart Code extension version 2.13.0

[✓] Connected devices (1 available)
    • iPad Pro (12.9-inch) (2nd generation) • D8D24435-C465-4403-B74F-E8DD32DDD30A • ios • iOS 11.4 (simulator)

• No issues found!

【问题讨论】:

  • 不用担心 - 我整天都在寻找这个问题的答案,终于找到了一个有效的修复方法 - 'flutter channel master' 然后是 'flutter clean' 和 'flutter run'
  • 几周前我遇到了同样的问题,我刚刚删除了flutter文件夹并从同一个存储库中克隆了它,它对我有用。
  • 如果您在使用 Firebase 的项目中遇到该问题,请查看 this answer here at SO

标签: ios xcode dart flutter


【解决方案1】:
  1. flutter run [new project] 然后将 iOS 文件夹替换为已存在的项目。 (您需要备份现有项目的 iOS 文件夹。)

  2. 将现有项目中的 ios/Runner 替换为新的 iOS 文件夹。

  3. Xcode 设置与现有项目相同。

如果出现iOS版本问题,修改Podfile。

deployment_target = '11.0'
        post_install do |installer|
        installer.generated_projects.each do |project|
            project.targets.each do |target|
                target.build_configurations.each do |config|
                    config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = deployment_target
                end
            end
            project.build_configurations.each do |config|
                config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = deployment_target
            end
        end
    end
  1. 然后,cd ios,pod install。

  2. 颤动运行。

【讨论】:

    【解决方案2】:

    对于任何来这里的人来说都是 2021

    用这个替换你的 pod 文件

    platform :ios, '12.0'
    
    ENV['COCOAPODS_DISABLE_STATS'] = 'true'
    
    project 'Runner', {
      'Debug' => :debug,
      'Profile' => :release,
      'Release' => :release,
    }
    
    def flutter_root
      generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
      unless File.exist?(generated_xcode_build_settings_path)
        raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
      end
    
      File.foreach(generated_xcode_build_settings_path) do |line|
        matches = line.match(/FLUTTER_ROOT\=(.*)/)
        return matches[1].strip if matches
      end
      raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
    end
    
    require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
    
    flutter_ios_podfile_setup
    
    def flutter_install_ios_plugin_pods(ios_application_path = nil)
      ios_application_path ||= File.dirname(defined_in_file.realpath) if self.respond_to?(:defined_in_file)
      raise 'Could not find iOS application path' unless ios_application_path
    
      symlink_dir = File.expand_path('.symlinks', ios_application_path)
      system('rm', '-rf', symlink_dir) # Avoid the complication of dependencies like FileUtils.
    
      symlink_plugins_dir = File.expand_path('plugins', symlink_dir)
      system('mkdir', '-p', symlink_plugins_dir)
    
      plugins_file = File.join(ios_application_path, '..', '.flutter-plugins-dependencies')
      plugin_pods = flutter_parse_plugins_file(plugins_file)
      plugin_pods.each do |plugin_hash|
        plugin_name = plugin_hash['name']
        plugin_path = plugin_hash['path']
        if (plugin_name && plugin_path)
          symlink = File.join(symlink_plugins_dir, plugin_name)
          File.symlink(plugin_path, symlink)
    
          if plugin_name == 'flutter_ffmpeg'
              pod 'flutter_ffmpeg/full-lts', :path => File.join('.symlinks', 'plugins', plugin_name, 'ios')
          else
              pod plugin_name, :path => File.join('.symlinks', 'plugins', plugin_name, 'ios')
          end
        end
      end
    end
    
    target 'Runner' do
      use_frameworks!
      use_modular_headers!
    
      flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
    end
    
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        flutter_additional_ios_build_settings(target)
      end
    end
    

    然后运行

    flutter pub get
    cd ios
    pod install
    

    编辑

    如果它不起作用,那么

    pod update
    flutter clean
    flutter run
    

    @信用Latalus

    【讨论】:

    • 不需要use_modular_headers!
    • 大声告诉人们用一揽子复制粘贴替换他们的整个 Podfile 不是吗,首席
    • 为我工作!!
    • 这对我有用!非常感谢!
    • 这个工作,完全复制一个 pod 文件 - 好/坏我们总是可以检查代码对吗?所以没有问题。 :-)
    【解决方案3】:

    这样做

    $rm ios/Flutter/Flutter.podspec
    $flutter clean
    

    然后运行

    flutter pub get
    

    pod install
    

    【讨论】:

      【解决方案4】:

      对我有用的是改变:

      #include "Flutter.h"
      

      #include <Flutter/Flutter.h>
      

      【讨论】:

        【解决方案5】:

        我猜这个问题是由中断 cocoapods 安装引起的。这是修复:

        • 从您的项目中删除 ios/Flutter/Flutter.framework
        • 在 ios 目录中运行pod install。应该生成Flutter.framework,包括Headers/Flutter.h文件
        • 运行构建。现在应该一切正常

        虽然切换到不同的 Flutter 可能会奏效,但它并不能真正解决缓存损坏的问题。请记住,Flutter 的 master 和 beta 分支不适合生产版本。

        【讨论】:

        • 这个解决方案对我有用(Flutter Channel stable, v1.17.1, on Mac OS X 10.15.3)
        • 就我而言,我什至没有 Flutter.framework,我只运行了 pod install 就可以了,非常感谢!
        【解决方案6】:

        当我尝试在我的颤振项目中添加一个分享按钮时,我遇到了这个问题。

        我通过以下步骤解决它:

        1. 检查您的pubspec.yaml 文件。
        2. 您应该确定您的 pod 文件和 cocoapods。为此,您应该在终端中按照以下步骤操作:Cannot Install Cocoapods - No podfile found in the project directory

        【讨论】:

          【解决方案7】:

          我整天都在寻找这个问题的答案,终于找到了一个有效的修复程序,在你的终端中运行它:

          颤振通道大师

          颤抖干净

          颤动运行

          我认为这只是一个尚未进入主频道的颤振错误/不兼容。

          【讨论】:

          • 这个答案两年后,问题仍然存在。 不要在生产中使用 Flutter 的主通道。
          • master 是流血的错误边缘dev 少所以beta 更稳定stable 公开发布如果beta 工作,你有更好的机会拥有更稳定的代码。
          猜你喜欢
          • 1970-01-01
          • 2021-07-17
          • 2021-09-04
          • 2021-09-29
          • 1970-01-01
          • 1970-01-01
          • 2021-11-18
          • 2021-07-21
          • 2021-03-26
          相关资源
          最近更新 更多