0

When trying to install pod packages for iOS with nx run <my_package_name>:pod-install, this occurs:

$ nx run app:pod-install

> nx run app:pod-install

Running `pod install` from "/Users/.../cites/packages/app/ios"
Command failed: pod install
Ignoring ffi-1.15.4 because its extensions are not built. Try: gem pristine ffi --version 1.15.4
Ignoring ffi-1.15.4 because its extensions are not built. Try: gem pristine ffi --version 1.15.4
Ignoring ffi-1.15.4 because its extensions are not built. Try: gem pristine ffi --version 1.15.4
...
LoadError - dlopen(/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle, 0x0009): tried: '/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle' (no such file), '/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')) - /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi_c.bundle
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
...

enter image description here

Context

Environment:

  • macOS M1 (Silicon)
  • react@18.2.0
  • react-dom@18.2.0
  • react-native@0.71.8
  • nx@16.3.0-beta.8"
  • @nx/react-native@16.3.0-beta.8

Install pods via terminal cd packages/app/ios && pod install.

Guillem Puche
  • 1,199
  • 13
  • 16

1 Answers1

0

The problem is related to a mismatch between my system architecture and the architecture that the ffi gem is trying to use. Specifically, it says that it's trying to use ffi version 1.15.5 for the arm64 architecture, but your system is x86_64.

This is a common issue when running certain Ruby gems on newer Macs with the M1 chip, which uses the arm64 architecture. However, most gems, including ffi, have been traditionally built for x86_64.

To use Rosetta 2 in M1 chip, we need to translate the x86_64 instructions to arm64.

The command lines to solve this solution are found here How to run CocoaPods on Apple Silicon (M1).

Steps

1 - Install global cocoapod package ffi

Open your terminal and run this command: sudo arch -x86_64 gem install ffi.

2 - Change the Nx package settings

In file packages/<your_package_name>/project.json.

I update the Nx command run-ios (default value on Nx documentation) and pod-install:

    "run-ios": {
      "executor": "@nx/react-native:run-ios",
      "options": {
        "simulator": "iPhone 14 Pro Max",
        "install": false
      }
    },
    "pod-install": {
      "executor": "nx:run-commands",
      "options": {
        "cwd": "packages/app/ios",
        "command": "arch -x86_64 pod install"
      }
    },
    "pod-install-non-arm64": {
      "executor": "@nx/react-native:pod-install",
      "options": {}
    },

enter image description here

Extra

I had little space on my Mac. While I was installing pod packages, Hermes Engine couldn't been installed.

The reason was Hermes Engine requires more than 1Gb of storage, as pointed here https://github.com/facebook/react-native/issues/31505#issuecomment-1050906080.

This was the error:

Installing ReactCommon (0.71.8)
Installing SocketRocket (0.6.0)
Installing Yoga (1.14.0)
Installing YogaKit (1.18.1)
Installing boost (1.76.0)
Installing fmt (6.2.1)
Installing glog (0.3.5)
Installing hermes-engine (0.71.8)
[!] Error installing hermes-engine
[!] /usr/bin/tar xf /var/folders/ys/spt316fs5sxck01gjy40s1rc0000gn/T/d20230526-23438-3wta30/file.tgz -C /var/folders/ys/spt316fs5sxck01gjy40s1rc0000gn/T/d20230526-23438-3wta30
./destroot/Library/Frameworks/universal/hermes.xcframework/ios-arm64_x86_64-maccatalyst/hermes.framework/Versions/0/hermes: Write failed
./destroot/Library/Frameworks/universal/hermes.xcframework/ios-arm64_x86_64-simulator/hermes.framework/hermes: Write failed
./destroot/Library/Frameworks/universal/hermes.xcframework/ios-arm64_x86_64-simulator/hermes.framework/Info.plist: Can't create 'destroot/Library/Frameworks/universal/hermes.xcframework/ios-arm64_x86_64-simulator/hermes.framework/Info.plist'
./destroot/include/jsi/: Can't create 'destroot/include/jsi'
./destroot/include/hermes/: Can't create 'destroot/include/hermes'
Guillem Puche
  • 1,199
  • 13
  • 16