Skip to content

Instantly share code, notes, and snippets.

@badsyntax
Last active March 11, 2024 18:25
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save badsyntax/72c5c965fcaefe66d049a8c2cdf34198 to your computer and use it in GitHub Desktop.
Save badsyntax/72c5c965fcaefe66d049a8c2cdf34198 to your computer and use it in GitHub Desktop.
Some tips to working with react-native 0.64 on an Apple M1 Silicon chip

My env:

  • cocoapods 1.10.1
  • xcode 12.4
  • macos big sur 11.2.3
  • react-native 0.64

iOS

The iOS simulator build won't "just work". If you get errors like ld: library not found for... or swift compiler errors, then you need to disable arm64 for the simulator build.

Ensure arm64 is excluded for the simulator build in the main project. Here's a reference:

In Podfile, set EXCLUDED_ARCHS[sdk=iphonesimulator*] = 'arm64' for pods:

post_install do |installer|
  react_native_post_install(installer)

  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      # Disable arm64 builds for the simulator
      config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
    end
  end
end

You'll need to re-install pods after making this change:

cd ios
rm -rf Pods Podfile.lock
pod install

Some libraries/pods will STILL have arch issues installing. You might get errors like missing compatible arch in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.0/lib/ffi_c.bundle, in which you will have to use Rosetta:

sudo arch -x86_64 gem install ffi
arch -x86_64 pod install

You won't be able to "Distribute" (create an .ipa from an archive build). You'll get an error like "IPA processing failed". This seems to be a bug with xcode 12.4. You will need to open XCode with Rosetta to fix this.

If you're using xcodebuild to generate an .ipa, you need to prepend arch -x86_64 to the command:

# Create the .ipa from the archive
arch -x86_64 xcodebuild \
  -exportArchive \
  -archivePath MyApp.xcarchive \
  -exportPath MyAppExported \
  -exportOptionsPlist ExportOptions.plist

Hermes

I couldn't get hermes to build. I think this will be fixed in react-native 0.65, see: facebook/hermes#475 & react-native-community/releases#223

Android

I have no problems building the project but the emulator does not support arm64. There is an Android Emulator M1 Preview but it has a few restrictions, like not having a working browser. To workaround this you can use a physical device attached via usb.

@enzzoperez
Copy link

thanks!, this worked for me fixing an error with a vision-camera frame-processor

@vsheyanov
Copy link

Ended up here while trying to fix same as @enzzoperez error with frame-processor library that is outdated.
In my case app was running fine in XCode, but was failing in Terminal. Running terminal with Rosetta "solved" the issue. It's not solving of course, but at least it runs.
Thanks for the reminder about Rosetta.

@samsiegart
Copy link

samsiegart commented Sep 9, 2023

You are a lifesaver. I might also mention I ran into this issue "Yoga.cpp : Use of bitwise '|' with boolean operands" in xcode 14.3, which I fixed using sed to patch like https://github.com/chainapsis/keplr-wallet/blob/366226e75de84a5caa8f831a847f7ced8cdd4c34/packages/mobile/scripts/start-ios.sh

@felipe-script
Copy link

felipe-script commented Mar 11, 2024

thx bro this worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment