Skip to content

Instantly share code, notes, and snippets.

@tj-mc
Forked from badsyntax/react-native-apple-m1.md
Created May 20, 2021 06:51
Show Gist options
  • Save tj-mc/657af76c4d4edc5b2713738e5d273924 to your computer and use it in GitHub Desktop.
Save tj-mc/657af76c4d4edc5b2713738e5d273924 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.

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