错误场景:
Xcode通过NSTask 或 NSAppleScript执行pod指令,反馈错误信息
env: ruby_executable_hooks: No such file or directory
// apple脚本执行shell pod指令
NSString *source = @"do shell script "/usr/local/bin/pod --version";
// 初始化apple脚本对象
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:source];
/*
执行并反馈结果
得到errorInfo[NSAppleScriptErrorMessage]结果为
env: ruby_executable_hooks: No such file or directory
*/
NSAppleEventDescriptor *result = [appleScript executeAndReturnError:&errorInfo];
分析原因:
cocoapods安装位置出错以及rvm配置异常
解决方案:
which pod
# /Users/daniel/.rvm/rubies/ruby-2.6.0/bin/pod
# 出现上述类似打印说明rvm的配置是ruby-2.6.0,此时执行以下命令即可
rvm use system
# Now using system ruby.
which pod
# /usr/local/bin/pod
# 理论上能出现以上打印,就说明rvm配置正常了,但别高兴太早
pod --version
# Ignoring executable-hooks-1.6.0 because its extensions are not built. Try: gem pristine executable-hooks --version 1.6.0
# Traceback (most recent call last):
# 4: from /usr/local/bin/ruby_executable_hooks:24:in `<main>'
# 3: from /usr/local/bin/ruby_executable_hooks:24:in `eval'
# 2: from /usr/local/bin/pod:23:in `<main>'
# 1: from #/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
#/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)
# 上述是两个问题,一个个解决
# 先按照提示执行
sudo gem pristine executable-hooks --version 1.6.0
# 按照提示不加sudo,可能得到以下错误,反馈权限不够
# Ignoring executable-hooks-1.6.0 because its extensions are not built. Try: gem pristine executable-hooks --version 1.6.0
# Error loading RubyGems plugin "/Users/daniel/.gem/ruby/2.6.0/gems/executable-hooks-1.6.0/lib/rubygems_plugin.rb": cannot load such file -- executable-hooks/wrapper (LoadError)
# ERROR: While executing gem ... (Gem::FilePermissionError)
# You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
pod --version
# 继续执行,理论上executable-hooks的错误会消失
# 再执行以下两条指令,就可彻底解决问题
sudo gem uninstall cocoapods
sudo gem install -n /usr/local/bin cocoapods
# 验证
pod --version
# 1.9.3
# 大功告成!
# 再回到xcode用NSTask或者NSAppleScript执行/usr/local/bin/pod相关指令就不会再出错了