73

I'm trying to build a React Native project on a MacBook Pro with a M1 architecture, for iOS simulator.

The project built nicely on Intel architecture.

It also build on device and archive well on M1. But not on simulator.

I had this classical error when switching to the M1 chipset.

in /project-folder/ios/Pods/OpenSSL-Universal/ios/lib/libcrypto.a(cryptlib.o), building for iOS Simulator, but linking in object file built for iOS, file '/project-folder/ios/Pods/OpenSSL-Universal/ios/lib/libcrypto.a' for architecture arm64

I added arm64 to excluded architectures.

I also added the following snippet but it also react the same way without it.

post_install do |installer|
  installer.pods_project.build_configurations.each do |config|
    config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
  end
end

Now I have:

/project-folder/ios/ProjectName.xcodeproj The linked library 'libPods-ProjectName.a' is missing one or more architectures required by this target: x86_64.

I tried to add x86_64 on the list of architectures of the project, with no results.

I'm building from Xcode IDE. This error message appears for all iPhones I tried: 8, 11, 12 and all targets I tried: iOS 9, 10 and 13.

ricardopereira
  • 11,118
  • 5
  • 63
  • 81
Xiiryo
  • 3,021
  • 5
  • 31
  • 48
  • Are you using any specific version of the `OpenSSL-Universal` pod? It looks like all of "i386 armv7 armv7s x86_64 arm64" slices are already included in the version 1.0.2.20 of the pod against the libcrypto library. So it could be a version conflict. – Ayan Sengupta Dec 19 '20 at 19:35
  • No. I think it is not linked with Open SSL, it is just that it is the first library that is called. This is an higher level issue. – Xiiryo Dec 20 '20 at 20:52
  • The issue with open SSL is solved when excluding arm64 – Xiiryo Dec 20 '20 at 22:49
  • Great! Any idea how did it solve itself since the open SSL binary already has arm64 slice in it. So I'm really curious. – Ayan Sengupta Dec 21 '20 at 13:59
  • I excluded arm64 both on Pods and project but I still have the same problem. @Xiiryo have u solved it somehow? I'm on a MacBook with Apple Silicon too. – DxW Dec 31 '20 at 11:29
  • Hi, not yet solved, I run on device for the time being. But it would be nice to have the simulators to explore the aspect on the different sizes. – Xiiryo Jan 01 '21 at 14:15

5 Answers5

141

I had the same issue and finally, I fixed it. There are 2 main reasons for the errors:

  1. arm64 architecture support & and Xcode 12 compatible version have not been provided by many popular third party libraries yet (like Firebase, AFNetworking, etc). Xcode 11 used to automatically translate building for arm64 for the simulator into building for x86_64, but now that arm64 is a valid simulator architecture (it’s the Apple Silicon architecture), that translation no longer occurs.

  2. Because the Valid Architectures build setting has been removed from Xcode 12, the Project file, opened in Xcode 12, will auto-generate a VALID_ARCHS macro in User-Defines, and this macro will make the build fail.

I follow all steps in this post: https://medium.com/@khushwanttanwar/xcode-12-compilation-errors-while-running-with-ios-14-simulators-5731c91326e9

Final step was updating all pods by running below command inside the project folder:

pod deintegrate
pod update

Then I exclude the arm64 for the Simulator architecture, both from main project and the Pod project.

Xcode build settings

Clean the project ( + + k) then run.

ricardopereira
  • 11,118
  • 5
  • 63
  • 81
Bek
  • 1,426
  • 1
  • 5
  • 2
  • 1
    Thank you for the in-depth explanation and link out to further reading. Thorough, I understand not just the fix, but why the fix works. – zkwentz Apr 08 '21 at 14:41
  • This keeps not working for me, but I swear it worked on another project before. Also, for some reason the excluded-architectures in my Pods project keep getting reset. The only thing that works is launching it from a rosetta terminal. – SeanMC Jan 20 '22 at 05:13
30

For me opening Xcode in Rosetta mode was what solved the problem. You may have to remove DerivedData also at: /Users/<username>/Library/Developer/Xcode/DerivedData

enter image description here

You can install Rosetta by running: softwareupdate --install-rosetta

Also it seems OS prompts you to install if trying to open an app that requires Rosetta: https://support.apple.com/en-us/HT211861

Waltari
  • 1,052
  • 1
  • 30
  • 64
13

XCode 12.5 broke most of the above answers. For those using XCode 12.5 and react-native 0.64.2, I wrote up a little guide to get things working:

https://github.com/aiba/react-native-m1/blob/main/README.md

Aaron Iba
  • 625
  • 5
  • 14
3

I had the same issue on my M1 Mac and here is what I did to fix this:

  1. brew install watchman
    if you don't have node => brew install node
  2. sudo arch -x86_64 gem install ffi
  3. add this code at the end of the pod file which is inside ios folder:
post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings["ONLY_ACTIVE_ARCH"] = "NO"
      end
    end
  end
  1. cd ios/ && arch -x86_64 pod install.

  2. run Xcode with Rosetta.
    enter image description here.
    You can install Rosetta by running: softwareupdate --install-rosetta

  3. exclude architecture arm64. enter image description here

  4. clean build - open xcode then press Command + Shift + K


  1. If you're using nvm try to replace NODE_BINARY=node with the actual result of the which node command, which in my case looks something like this:enter image description here
    enter image description here

Shoutout to these answers: one two three

Vlad R
  • 1,851
  • 15
  • 13
  • have you tried to launch without rosetta? I can but empty project (create-react-native-app). But main project only can launch with rosetta. Want to launch without because rossetta slower. What do you think? – arkan4ik92 Apr 12 '22 at 23:01
1

I was getting this error when using run-ios command targeting a simulator. I just added below script to the post install area of Podfile, did pod install and build was successful when i ran same run-ios command targeting simulator. Using Xcode 13.2.1 for reference.

installer.pods_project.build_configurations.each do |config|
    config.build_settings["ONLY_ACTIVE_ARCH"] = "NO"
end

Hope someone gets help from this.

Edit: I am on a M1 machine and used rosetta terminal for creating the project but all other pod install done from non-rosetta terminal. my cocoapods and ffi installations were also from rosetta terminal including brew installation as well.

Mahesh Agrawal
  • 3,348
  • 20
  • 34