You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native CLI项目搭建遇阻:ffi依赖安装失败求助

React Native项目创建及bundle install依赖报错问题

问题描述

执行npx react-native projectname创建项目时,项目仅部分生成。后续运行bundle install时触发以下错误:

  1. Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
  2. An error occurred while installing ffi (1.15.5), and Bundler cannot continue. Make sure that "gem install ffi -v '1.15.5' --source 'https://rubygems.org/'" succeeds before bundling.

完整报错日志

Using atomos 0.1.3
Using bundler 2.1.4
Using claide 1.1.0
Using fuzzy_match 2.0.4
Using nap 1.1.0
Using netrc 0.11.0
Fetching ffi 1.15.5
Installing ffi 1.15.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: █████████████████████s/React
Native/uber/vendor/bundle/ruby/2.7.0/gems/ffi-1.15.5/ext/ffi_c
█████████████████████/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0 -r ./siteconf20221129-56735-3mfz1o.rb
extconf.rb
checking for ffi_prep_closure_loc() in -lffi… no
checking for ffi_prep_closure_loc() in -llibffi… no
checking for ffi_prep_closure_loc() in -llibffi-8… no
checking for whether -Wl,--exclude-libs,ALL is accepted as LDFLAGS… no
checking for whether -pthread is accepted as LDFLAGS… yes
creating extconf.h
creating Makefile

current directory: █████████████████████React
Native/uber/vendor/bundle/ruby/2.7.0/gems/ffi-1.15.5/ext/ffi_c
make "DESTDIR=" clean

current directory: █████████████████████React
Native/uber/vendor/bundle/ruby/2.7.0/gems/ffi-1.15.5/ext/ffi_c
make "DESTDIR="
/bin/sh: -c: line 0: unexpected EOF while looking for matching
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** █████████████████████ Error 2

make failed, exit code 2

Gem files will remain installed in █████████████████████/React
Native/uber/vendor/bundle/ruby/2.7.0/gems/ffi-1.15.5 for inspection.
Results logged to █████████████████████/React
Native/uber/vendor/bundle/ruby/2.7.0/extensions/arm64-darwin-21/2.7.0/ffi-1.15.5/gem_make.out

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

In Gemfile:
  cocoapods was resolved to 1.11.3, which depends on
    cocoapods-core was resolved to 1.11.3, which depends on
      typhoeus was resolved to 1.4.0, which depends on
        ethon was resolved to 0.16.0, which depends on
          ffi

已尝试操作

已成功执行gem install ffi -v '1.15.5' --source 'https://rubygems.org/'安装指定版本的ffi,但bundle install仍提示该依赖未安装。

环境信息

  • Ruby版本: ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [arm64-darwin21]
  • pod版本: 1.11.3

解决方案

针对M1芯片Mac(arm64架构)的兼容性问题,可按以下步骤操作:

  1. 清理bundle缓存

    bundle clean --force
    
  2. 通过Rosetta转译安装ffi

    arch -x86_64 gem install ffi -v '1.15.5'
    
  3. 以x86架构运行bundle install

    arch -x86_64 bundle install
    
  4. 备选方案:重置本地bundle依赖
    如果上述步骤无效,删除项目本地依赖目录后重新安装:

    rm -rf vendor/bundle
    arch -x86_64 bundle install
    
  5. 验证依赖路径一致性
    检查全局gem与bundle的依赖路径是否匹配,若不匹配手动指定:

    gem list ffi
    bundle config set local.ffi $(gem which ffi | sed -n 's/\/lib.*//p')
    

内容的提问来源于stack exchange,提问作者5ecured

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 09:05:38