React Native安装Ruby Gems

w51jfk4q  于 12个月前  发布在  Ruby
关注(0)|答案(1)|浏览(188)

当我运行npx react-native init Project来创建新的React Native项目时,我得到了这个错误:

✔ Downloading template
✔ Copying template
✔ Processing template
✖ Installing Ruby Gems
error Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
Fetching rexml 3.2.6
Installing rexml 3.2.6
Fetching CFPropertyList 3.0.6
Installing CFPropertyList 3.0.6
Fetching concurrent-ruby 1.2.2
Installing concurrent-ruby 1.2.2
Fetching i18n 1.14.1
Installing i18n 1.14.1
Fetching minitest 5.20.0
Installing minitest 5.20.0
Fetching tzinfo 2.0.6
Installing tzinfo 2.0.6
Fetching zeitwerk 2.6.11
Installing zeitwerk 2.6.11
Fetching activesupport 6.1.7.6
Installing activesupport 6.1.7.6
Fetching public_suffix 4.0.7
Installing public_suffix 4.0.7
Fetching addressable 2.8.5
Installing addressable 2.8.5
Fetching httpclient 2.8.3
Installing httpclient 2.8.3
Fetching json 2.6.3
Installing json 2.6.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/Users/qrivnel/Desktop/Project/vendor/bundle/ruby/2.6.0/gems/json-2.6.3/ext/json/ext/generator
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r
./siteconf20230924-69529-n3hcgy.rb extconf.rb
creating Makefile

current directory:
/Users/qrivnel/Desktop/Project/vendor/bundle/ruby/2.6.0/gems/json-2.6.3/ext/json/ext/generator
make "DESTDIR=" clean

current directory:
/Users/qrivnel/Desktop/Project/vendor/bundle/ruby/2.6.0/gems/json-2.6.3/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
In file included from ./../fbuffer/fbuffer.h:5:
In file included from
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10:
fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
         ^~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10:
note: did not find header 'config.h' in framework 'ruby' (loaded from
'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks')
1 error generated.
make: *** [generator.o] Error 1

make failed, exit code 2

Gem files will remain installed in
/Users/qrivnel/Desktop/Project/vendor/bundle/ruby/2.6.0/gems/json-2.6.3 for
inspection.
Results logged to
/Users/qrivnel/Desktop/Project/vendor/bundle/ruby/2.6.0/extensions/universal-darwin-22/2.6.0/json-2.6.3/gem_make.out

An error occurred while installing json (2.6.3), and Bundler cannot continue.
Make sure that `gem install json -v '2.6.3' --source 'https://rubygems.org/'`
succeeds before bundling.

In Gemfile:
  cocoapods was resolved to 1.13.0, which depends on
    cocoapods-core was resolved to 1.13.0, which depends on
      algoliasearch was resolved to 1.27.5, which depends on
        json
✖ Installing Ruby Gems
error Looks like your iOS environment is not properly set. Please go to https://reactnative.dev/docs/environment-setup?os=macos&platform=android and follow the React Native CLI QuickStart guide for macOS and iOS.
info Run CLI with --verbose flag for more details.

我用brew install cocoapods安装cocoapods。pod--版本1.13.0
我也尝试了sudo gem安装cocapods之前brew安装,我得到了这个:`密码:构建本地扩展。这可能要花点时间。。错误:安装cocoapods时出错:错误:无法生成gem本机扩展。

current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.16.1/ext/ffi_c

/System/Library/Frameworks/Ruby. framework/Versions/2.6/usr/bin/ruby-I/System/Library/Frameworks/Ruby. framework/Versions/2.6/usr/lib/ruby/2.6.0-r./siteconf20230924 - 70457-cgucg. rb extconf. rb * extconf. rb failed * 无法创建Makefile由于某些原因,可能缺少必要的库和/或头文件。有关详细信息,请检查mkmf.log文件。您可能需要配置选项。
提供的配置选项:- -with-opt-dir--without-opt-dir--with-opt-include--without-opt-include =${opt-dir}/include--with-opt-lib--without-opt-lib =${opt-dir}/lib--with-make-prog--without-make-prog--srcdir =.- -curdir--ruby =/System/Library/Frameworks/Ruby。framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)--with-ffi_c-dir--without-ffi_c-dir--with-ffi_c-include--without-ffi_c-include =${ffi_c-dir}/include--with-ffi_c-lib--without-ffi_c-lib =${ffi_c-dir}/lib--enable-debug--disable-debug--enable-system-libffi--disable-system-libffi--without-libffi-config--without-pkg-config--without-pkg-config/System/Library/Frameworks/Ruby. framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf. rb:四百六十七:在/System/Library/Frameworks/Ruby中的try_link0 '中的try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in块中。framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir. rb:九十三:在/System/Library/Frameworks/Ruby中的mktmpdir' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in try_link0'中。framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf. rb:570:在try_link' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:672:in中,try_ldflags '来自/System/Library/Frameworks/Ruby。framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf. rb:一八三二年:在pkg_config' from extconf.rb:9:in system_libffi_usable中?'from extconf. rb:46:in `'
要查看此扩展无法编译的原因,请查看mkmf.log,可以在这里找到:
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-22/2.6.0/ffi-1.16.1/mkmf.log
extconf失败,退出代码% 1
Gem文件将继续安装在/Library/Ruby/Gems/2.6.0/gems/ffi-1.16.1中以供检查。结果记录到/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-22/2.6.0/ffi-1.16.1/gem_make. out

pxiryf3j

pxiryf3j1#

我今天遇到了和你一样的问题,所以我将一步一步地告诉你我必须做些什么才能让我的RN“Hello world”应用程序运行,希望你不必做所有这些来让你的应用程序运行。
您遇到的问题是,您可能正在使用macOS上预装的系统Ruby版本(这是旧版本的Ruby)。你可以通过运行
ruby -v
它将显示类似于2.6.2(目前我的OS Ruby版本)的内容。您可以使用rbenv安装您自己的Ruby版本(也有其他Ruby管理器):https://github.com/rbenv/rbenv
基本上你这样做(你必须安装自制软件:https://brew.sh/):

brew install rbenv ruby-build

rbenv init

rbenv install 3.2.2

rbenv rehash

然后在你的终端上输入以下内容,在.zshrc(或.bashrc,这取决于你使用的shell)中添加一行:

echo 'eval "$(~/.rbenv/bin/rbenv init - zsh)"' >> ~/.zshrc

如果重新启动终端,当输入ruby -v时,应该可以看到3.2.2(或您安装的任何版本)ruby版本
接下来你需要的是椰子:

sudo gem install cocoapods

因此,如果您在终端中输入pod --version,它应该显示当前版本,但它可能会显示“Bad CPU type in executable”错误。如果您尝试在基于旧英特尔芯片的M1芯片上执行命令,则可能会发生这种情况。要解决这个问题,请安装Rossetta 2:https://apple.stackexchange.com/questions/408375/zsh-bad-cpu-type-in-executable
只需在终端中输入以下内容:

softwareupdate --install-rosetta

现在您应该能够执行pod --versionpod install
在所有这些之后,仍然有一个问题与activesupport,这是cocoapods的一部分。问题是CocoaPods没有使用一个确切版本的activesupport gem,虽然它需要7.0.8,但它引入了7.1.0,这破坏了它。我在这里找到了一个解决方案:https://github.com/facebook/react-native/issues/39832
我只是要复制粘贴解决方案从链接(作者:Stephen-Pearce):
在根目录中更新Gemfile,如下所示:

gem 'activesupport', '~> 7.0', '<= 7.0.8'

然后在根目录下运行bundle update --bundler,然后在ios目录下运行bundle installbundle exec pod install,一切都应该正常。
希望这能帮助您解决问题,或者您不必执行所有这些步骤来运行RN应用程序。

相关问题