【问题标题】:Flutter iOS cannot build due to modular header settings in podfile由于 podfile 中的模块化标头设置,Flutter iOS 无法构建
【发布时间】:2020-10-01 19:37:12
【问题描述】:

我有一个运行良好的颤振应用程序。我正在更新我的颤振版本和一些插件的版本(在最新的 XCode 版本 11 上)。我无法再构建我的应用程序,因为发生以下两种情况之一:

1) 如果我没有“use_modular_headers!”在我的 podfile 中,尝试运行 pod install 时出现此错误:

The Swift pod `DKPhotoGallery` depends upon `SDWebImage`, which does not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.

2) 如果我添加“use_modular_headers!”到 podfile,然后我可以成功安装 podfile,但是在构建时失败并出现此错误:

fatal error: module map file '/Users/mbpro/Documents/Perkl/ios/Pods/Headers/Private/openssl_grpc/BoringSSL-GRPC.modulemap' not found

我发现的第二个错误是因为 GRPC 不支持模块化标题。这就是我卡住的地方,因为由于颤振从 pubspec 动态生成 podfile 的方式,模块化标头似乎是全局打开或关闭的,我无法专门为特定 pod 打开模块化标头。

这是我的 pubspec 依赖项列表:

  cloud_firestore: 0.13.6
  firebase_auth: 0.16.1
  firebase_core:
  firebase_database:
  firebase_storage:
  firebase_messaging:
  google_sign_in:
  image_picker:
  image_cropper:
  intl:
  flutter_sound:
  flutter_launcher_icons:
  flushbar:
  file_picker:
  path_provider:
  #audioplayers:
  provider:
  sliding_up_panel:
  font_awesome_flutter:
  marquee:

对此的任何帮助将不胜感激!它完全关闭了我的开发,因为升级后我无法构建来测试任何东西。

编辑:Flutter Doctor -v 输出(一切看起来都很好)

[✓] Flutter (Channel stable, v1.17.3, on Mac OS X 10.15.5 19F101, locale en-US)
    • Flutter version 1.17.3 at /Users/mbpro/Downloads/flutter
    • Framework revision b041144f83 (8 days ago), 2020-06-04 09:26:11 -0700
    • Engine revision ee76268252
    • Dart version 2.8.4


[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/mbpro/Library/Android/sdk
    • Platform android-29, build-tools 29.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_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.5, Build version 11E608c
    • CocoaPods version 1.9.3

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 44.0.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build
      1.8.0_202-release-1483-b49-5587405)

[✓] Connected device (1 available)
    • iPhone SE (2nd generation) • 9FC22937-91AB-4F22-BB1E-20FFB1CAF4C8 • ios •
      com.apple.CoreSimulator.SimRuntime.iOS-13-5 (simulator)

• No issues found!

【问题讨论】:

  • 您可以运行“颤振医生”并将结果粘贴到您的问题中吗?
  • 我进行了编辑,但 flutter doctor 中的一切似乎都很好。似乎我的一个 dart 插件使用了一个不能使用模块化标题的 iOS 框架,而另一个使用需要使用模块化标题的 iOS 库。但是通过 Flutter 设置 podfile 的方式,你不能只告诉某些 pod 使用模块化标题

标签: ios flutter flutter-dependencies podfile


【解决方案1】:

经过很长时间的搜索,答案很简单。

1- 导航到应用内的 ios 目录

2- 在文本编辑器中编辑 podfile

3- 搜索target 'Runner' do

4- 在下一行添加use_frameworks!

5- 保存并运行您的应用

例如,我的完整 podfile 看起来像这样在解决问题之前

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
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

target 'Runner' do

  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

解决问题后通过添加看起来像的额外行

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
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

target 'Runner' do
  use_frameworks!
  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

【讨论】:

  • 工作就像一个魅力!
  • 感谢它有效,我相信这个问题来自 file_picker,这应该是公认的答案
【解决方案2】:

我整天都在使用非常相似的插件列表来解决同样的问题。

使用这个答案: Using static libraries with CocoaPods 1.5 no such module at import

我能够如下修改flutter pod并构建项目:

# Uncomment this line to define a global platform for your project
platform :ios, '8.0'

inhibit_all_warnings! # ------------------> NEW

use_frameworks! # ------------------> NEW
dynamic_frameworks = ['BoringSSL-GRPC'] # ------------------> NEW

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}


def parse_KV_file(file, separator='=')
  file_abs_path = File.expand_path(file)
  if !File.exists? file_abs_path
    return [];
  end
  generated_key_values = {}
  skip_line_start_symbols = ["#", "/"]
  File.foreach(file_abs_path) do |line|
    next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
    plugin = line.split(pattern=separator)
    if plugin.length == 2
      podname = plugin[0].strip()
      path = plugin[1].strip()
      podpath = File.expand_path("#{path}", file_abs_path)
      generated_key_values[podname] = podpath
     else
      puts "Invalid plugin specification: #{line}"
     end
  end
  generated_key_values
end

target 'Runner' do
  # Flutter Pod

  copied_flutter_dir = File.join(__dir__, 'Flutter')
  copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
  copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
  unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
    # Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
    # That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
    # CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.

    generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
    unless File.exist?(generated_xcode_build_settings_path)
      raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
    end
    generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
    cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];

    unless File.exist?(copied_framework_path)
      FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
    end
    unless File.exist?(copied_podspec_path)
      FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
    end
  end

  # Keep pod path relative so it can be checked into Podfile.lock.
  pod 'Flutter', :path => 'Flutter'
  # Plugin Pods

  # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
  # referring to absolute paths on developers' machines.
  system('rm -rf .symlinks')
  system('mkdir -p .symlinks/plugins')
  plugin_pods = parse_KV_file('../.flutter-plugins')
  plugin_pods.each do |name, path|
    symlink = File.join('.symlinks', 'plugins', name)
    File.symlink(path, symlink)  
    pod name, :path => File.join(symlink, 'ios')
  end
end


pre_install do |installer|  # ------------------> NEW BLOCK
    installer.pod_targets.each do |pod|
puts "Evaluating static framework for pod #{pod.name}"
        if dynamic_frameworks.include?(pod.name)
            puts "Overriding the static_framework method for #{pod.name}"
            pod pod.name, :modular_headers => false        
end
    end
end

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

这是我第一次在IOS中构建应用程序,总构建时间约为35m(!),我不知道它是否与此修复有关,或者它是其他什么。

还尝试进行反向操作,所有动态和 DKPhotoGalley 静态,但这会导致构建失败,并出现 DKPhotoGallery 代码错误。

如果有人能提出更好的方法或对潜在问题的理解,那就太好了。

【讨论】:

    【解决方案3】:

    想通了。我将 file_picker 恢复为 1.6.3+2 现在我可以毫无问题地运行我的 iOS 应用程序。享受。希望您不要使用此版本之后添加到文件选择器的任何新功能。我很幸运到了我没有的地方。我相信这个突破性的变化就是原因。不管怎样,这对我有用,希望它对你有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-17
      • 2021-08-08
      • 2021-11-27
      • 2016-12-07
      • 2020-12-04
      • 1970-01-01
      • 2017-12-11
      • 2011-07-17
      相关资源
      最近更新 更多