背景:在运行Flutter项目的时候出现这个问题,找来找去找不到原因,还是stackoverflow比较香
I was working on a Flutter app and suddenly got the following error when I run
pod install
. I need to mention that I searched a lot and tried too many ways but unfortunately nobody had the exactundefined method 'each_child'
error. I also delete thePodfile.lock
and Pod folder as people said and didn't generate again :(
Error:
[!] 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>'
flutter doctor:
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!
Pods installed: (running 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
解决方案
The method dir.each_child
was introduced in Ruby 2.6, but you are using Ruby 2.3.0.
You should update Ruby to 2.6.0 or later 2.x version.
After Ruby updating you may also need to restart your IDE and re-install cocoapods.
就是说
dir.each_child
这方法是只在Ruby 2.6之后才有的,现在Ruby版本需要升级才行
安装Ruby 2.6.6之后Flutter还是使用2.5.1旧版本
检查下安装的ruby版本
rvm list
rvm 设置默认ruby版本
rvm 2.6.6 --default
image.png
网友评论