Erh*_*taş 7 ruby macos homebrew reactjs react-native
当我运行 npx react-native init Project 来创建新的 React Native 项目时,我收到此错误:
\n\xe2\x9c\x94 Downloading template\n\xe2\x9c\x94 Copying template\n\xe2\x9c\x94 Processing template\n\xe2\x9c\x96 Installing Ruby Gems\nerror Fetching gem metadata from https://rubygems.org/........\nResolving dependencies...\nFetching rexml 3.2.6\nInstalling rexml 3.2.6\nFetching CFPropertyList 3.0.6\nInstalling CFPropertyList 3.0.6\nFetching concurrent-ruby 1.2.2\nInstalling concurrent-ruby 1.2.2\nFetching i18n 1.14.1\nInstalling i18n 1.14.1\nFetching minitest 5.20.0\nInstalling minitest 5.20.0\nFetching tzinfo 2.0.6\nInstalling tzinfo 2.0.6\nFetching zeitwerk 2.6.11\nInstalling zeitwerk 2.6.11\nFetching activesupport 6.1.7.6\nInstalling activesupport 6.1.7.6\nFetching public_suffix 4.0.7\nInstalling public_suffix 4.0.7\nFetching addressable 2.8.5\nInstalling addressable 2.8.5\nFetching httpclient 2.8.3\nInstalling httpclient 2.8.3\nFetching json 2.6.3\nInstalling json 2.6.3 with native extensions\nGem::Ext::BuildError: ERROR: Failed to build gem native extension.\n\ncurrent directory:\n/Users/qrivnel/Desktop/Project/vendor/bundle/ruby/2.6.0/gems/json-2.6.3/ext/json/ext/generator\n/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I\n/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r\n./siteconf20230924-69529-n3hcgy.rb extconf.rb\ncreating Makefile\n\ncurrent directory:\n/Users/qrivnel/Desktop/Project/vendor/bundle/ruby/2.6.0/gems/json-2.6.3/ext/json/ext/generator\nmake "DESTDIR=" clean\n\ncurrent directory:\n/Users/qrivnel/Desktop/Project/vendor/bundle/ruby/2.6.0/gems/json-2.6.3/ext/json/ext/generator\nmake "DESTDIR="\ncompiling generator.c\nIn file included from generator.c:1:\nIn file included from ./../fbuffer/fbuffer.h:5:\nIn file included from\n/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:\n/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:\nfatal error: 'ruby/config.h' file not found\n#include "ruby/config.h"\n ^~~~~~~~~~~~~~~\n/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:\nnote: did not find header 'config.h' in framework 'ruby' (loaded from\n'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks')\n1 error generated.\nmake: *** [generator.o] Error 1\n\nmake failed, exit code 2\n\nGem files will remain installed in\n/Users/qrivnel/Desktop/Project/vendor/bundle/ruby/2.6.0/gems/json-2.6.3 for\ninspection.\nResults logged to\n/Users/qrivnel/Desktop/Project/vendor/bundle/ruby/2.6.0/extensions/universal-darwin-22/2.6.0/json-2.6.3/gem_make.out\n\nAn error occurred while installing json (2.6.3), and Bundler cannot continue.\nMake sure that `gem install json -v '2.6.3' --source 'https://rubygems.org/'`\nsucceeds before bundling.\n\nIn Gemfile:\n cocoapods was resolved to 1.13.0, which depends on\n cocoapods-core was resolved to 1.13.0, which depends on\n algoliasearch was resolved to 1.27.5, which depends on\n json\n\xe2\x9c\x96 Installing Ruby Gems\nerror 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.\ninfo Run CLI with --verbose flag for more details.\nRun Code Online (Sandbox Code Playgroud)\n我使用brew install cocoapods安装cocoapods。\npod --version\n1.13.0
\n我还在brew install之前尝试过 sudo gem install cocapods ,我得到了这个:\n`\n密码:\n构建本机扩展。这可能需要一段时间...\n错误:安装 cocoapods 时出错:\n错误:无法构建 gem 本机扩展。
\ncurrent directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.16.1/ext/ffi_c\nRun Code Online (Sandbox Code Playgroud)\n/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\n*** extconf.rb 失败 ***\n由于某种原因无法创建 Makefile,可能缺少\n必要的库和/或标头。检查 mkmf.log 文件以获取更多详细信息。您可能\n需要配置选项。
\n提供的配置选项:\n--with-opt-dir\n--without-opt-dir\n--with-opt-include\n--without-opt-include=${opt-dir}/include\ n--with-opt-lib\n--without-opt-lib=${opt-dir}/lib\n--with-make-prog\n--without-make-prog\n--srcdir= .\n--curdir\n--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)\n--with-ffi_c-dir\n--without- ffi_c-dir\n--with-ffi_c-include\n--without-ffi_c-include=${ffi_c-dir}/include\n--with-ffi_c-lib\n--without-ffi_c-lib=$ {ffi_c-dir}/lib\n--启用调试\n--禁用调试\n--启用系统libffi\n--禁用系统libffi\n--with-libffi-config\n --without-libffi-config\n--with-pkg-config\n--without-pkg-config\n/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6。 0/mkmf.rb:467:在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 try_link0'\n 中的块中 /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in mktmpdir' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in try_link0'\ n来自/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in try_link' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:672:in try_ldflags'\n来自/System/Library/Frameworks/Ruby.framework/Versions/ 2.6/usr/lib/ruby/2.6.0/mkmf.rb:1832:in pkg_config' from extconf.rb:9:in system_libffi_usable?'\n来自 extconf.rb:46:in `'
要了解此扩展无法编译的原因,请检查可在此处找到的 mkmf.log:
\n/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-22/2.6.0/ffi-1.16.1/mkmf.log
\nextconf 失败,退出代码 1
\nGem 文件将保留安装在 /Library/Ruby/Gems/2.6.0/gems/ffi-1.16.1 中以供检查。\n结果记录到 /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-22/ 2.6.0/ffi-1.16.1/gem_make.out
\n我今天遇到了和您一样的问题,所以我将一步步告诉您我必须做什么才能让我的 RN“Hello world”应用程序运行,希望您不必执行所有这些操作即可获得您的应用程序正在运行。
您遇到的问题是您可能使用的是 macOS 上预装的系统 Ruby 版本(这是 Ruby 的旧版本)。您可以通过运行来检查
ruby -v
它将显示类似 2.6.2 的内容(当前我的操作系统 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
Run Code Online (Sandbox Code Playgroud)
然后在终端中输入以下内容,将一行添加到 .zshrc (或 .bashrc,这取决于您使用的 shell):
echo 'eval "$(~/.rbenv/bin/rbenv init - zsh)"' >> ~/.zshrc
Run Code Online (Sandbox Code Playgroud)
如果重新启动终端,则在键入时应该能够看到 3.2.2(或您安装的任何版本)ruby 版本ruby -v
接下来你需要的是 cocoapods:
sudo gem install cocoapods
Run Code Online (Sandbox Code Playgroud)
因此,如果您pod --version在终端中输入内容,它应该显示当前版本,但它可能会显示“可执行文件中的 CPU 类型错误”错误。如果您尝试在基于较旧 Intel 芯片的 M1 芯片上执行命令,则可能会发生这种情况。要解决此问题,请安装 Rossetta 2:https://apple.stackexchange.com/questions/408375/zsh-bad-cpu-type-in -executable
只需在终端中输入:
softwareupdate --install-rosetta
Run Code Online (Sandbox Code Playgroud)
现在你应该能够做到pod --version并且pod 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'
Run Code Online (Sandbox Code Playgroud)
然后bundle update --bundler在根目录bundle install和bundle exec pod installios 目录中运行,一切都应该正常。
希望这可以帮助您解决问题,或者您不必执行所有这些步骤即可运行 RN 应用程序。
| 归档时间: |
|
| 查看次数: |
3636 次 |
| 最近记录: |