Flutter pod 安装问题 - #<Dir:0x00007fa6f7e2ec80> 的未定义方法 `each_child'

Posted

技术标签:

【中文标题】Flutter pod 安装问题 - #<Dir:0x00007fa6f7e2ec80> 的未定义方法 `each_child\'【英文标题】:Flutter pod install problem - undefined method `each_child' for #<Dir:0x00007fa6f7e2ec80>Flutter pod 安装问题 - #<Dir:0x00007fa6f7e2ec80> 的未定义方法 `each_child' 【发布时间】:2021-03-19 16:59:43 【问题描述】:

我正在开发一个 Flutter 应用程序,当我运行 pod install 时突然出现以下错误。 我需要提一下,我进行了很多搜索并尝试了太多方法,但不幸的是没有人有确切的undefined method 'each_child' 错误。 正如人们所说,我还删除了Podfile.lock 和 Pod 文件夹,并且没有再次生成:(

错误:

[!] An error occurred while processing the post-install hook of the Podfile.

undefined method `each_child' for #<Dir:0x00007f82a354e4f8>

/Users/vahidnaghash/Developer/flutter/packages/flutter_tools/bin/podhelper.rb:50:in `block in flutter_additional_ios_build_settings'
/Users/vahidnaghash/Developer/flutter/packages/flutter_tools/bin/podhelper.rb:47:in `each'
/Users/vahidnaghash/Developer/flutter/packages/flutter_tools/bin/podhelper.rb:47:in `flutter_additional_ios_build_settings'
/Users/vahidnaghash/androidStudioProjects/careberry_flutter/careberry/ios/Podfile:39:in `block (3 levels) in from_ruby'
/Users/vahidnaghash/AndroidStudioProjects/careberry_flutter/careberry/ios/Podfile:38:in `each'
/Users/vahidnaghash/AndroidStudioProjects/careberry_flutter/careberry/ios/Podfile:38:in `block (2 levels) in from_ruby'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-core-1.10.0/lib/cocoapods-core/podfile.rb:179:in `post_install!'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:897:in `run_podfile_post_install_hook'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:885:in `block in run_podfile_post_install_hooks'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.10.0/lib/cocoapods/user_interface.rb:145:in `message'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:884:in `run_podfile_post_install_hooks'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:329:in `block (2 levels) in create_and_save_projects'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/xcode/pods_project_generator/pods_project_writer.rb:61:in `write!'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:328:in `block in create_and_save_projects'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.10.0/lib/cocoapods/user_interface.rb:64:in `section'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:307:in `create_and_save_projects'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:299:in `generate_pods_project'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:178:in `integrate'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:166:in `install!'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.10.0/lib/cocoapods/command/install.rb:52:in `run'
/Library/Ruby/Gems/2.3.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.10.0/lib/cocoapods/command.rb:52:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.10.0/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:23:in `load'
/usr/local/bin/pod:23:in `<main>'

扑医生:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 1.25.0-5.0.pre.92, on Mac OS X 10.14.6 18G103 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.0)
[✓] IntelliJ IDEA Ultimate Edition (version 2020.2.1)
[✓] VS Code (version 1.49.1)
[✓] Connected device (2 available)

• No issues found!

已安装的 Pod:(运行 gem list --local | grep cocoapods

cocoapods (1.10.0)
cocoapods-core (1.10.0)
cocoapods-deintegrate (1.0.4)
cocoapods-downloader (1.4.0)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.0)
cocoapods-trunk (1.5.0)
cocoapods-try (1.2.0)

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

【问题讨论】:

【参考方案1】:

方法dir.each_childwas introduced in Ruby 2.6,但是你使用的是Ruby 2.3.0。

您应该update Ruby 到 2.6.0 或更高版本的 2.x 版本。

Ruby 更新后,您可能还需要重新启动 IDE 和 re-install cocoapods。

【讨论】:

【参考方案2】:

Dir#each_child 实例方法was introduced in Ruby 2.6,但您使用的是 2.3。

您应该更新到 Ruby 2.6 或更高版本。

请注意,Ruby 2.5 只引入了Dir.each_child 类方法,而不是Flutter 的podhelper.rb 使用的实例方法

Dir.new(configuration_engine_dir).each_child do |xcframework_file|
  # ...
end

【讨论】:

【参考方案3】:

我通过在终端中运行 flutter channel stable 将颤振通道从主通道更改为稳定通道。我猜主频道有错误!

【讨论】:

以上是关于Flutter pod 安装问题 - #<Dir:0x00007fa6f7e2ec80> 的未定义方法 `each_child'的主要内容,如果未能解决你的问题,请参考以下文章

Pod 无法更新或安装 - Dart/Flutter

Flutter 调试:警告:未安装 CocoaPods。跳过 pod 安装

Flutter pod 文件问题

不知道在哪里添加pod文件flutter ios安装

在 Flutter 中安装原生 iOS pod

M1 Mac 上的 Pod 安装错误 - 使用 shared_preferences 等本机代码的 Flutter 项目