Xcode error 'building for iOS Simulator, but linking in dylib built for iOS .. for architecture arm64' from Apple Silicon M1 Mac
Asked Answered
F

8

45

I have an app which compiles and runs fine in older Macs with Intel processors in physical devices & iOS simulators.

The same app also compiles and runs fine from newer Apple Silicon Mac with M1 processor with physical iPhone devices, but it refuses to be compiled for iOS simulator.

Without simulator support, debugging turn around time gets gets really long so I am trying to solve this issue. Not to mention Xcode preview feature isn't working either which is annoying.

The first error that I encountered without making any changes (but moved from Intel Mac to M1 Mac) is like below.

building for iOS Simulator, but linking in dylib built for iOS, file '/Users/andy/workspace/app/Pods/GoogleWebRTC/Frameworks/frameworks/WebRTC.framework/WebRTC' for architecture arm64

The Cocoapods library that I am using is GoogleWebRTC, and according to its doc, arm64 should be supported so I am baffled why above error is getting thrown. As I have said before, it compiles fine in real device which I believe is running on arm64.

According to the doc..

This pod contains the WebRTC iOS SDK in binary form. It is a dynamic library that contains the armv7, arm64 and x86_64 slices. Bitcode is not supported. Our currently provided API’s are Objective C only.

I searched online and it appears there appears to be 2 workarounds for this issue.

  1. The first one is by adding arm64 to Excluded Architectures
  2. The second option is to mark Build Active Architecture Only for Release build.

I don't exactly understand if above are necessary even when I am compiling my app on M1 Mac which is running under arm64 architecture, because the solution seems to be applicable only for for Intel Mac which does not support arm64 simulator, as for Intel Mac, simulators might have been running in x86_64, not with arm64, so solution #1 is not applicable in my case.

When I adapt the second change only, nothing really changes and the same error is thrown.

When I make both changes and tried building, I now get the following 2nd error during build. (not really 100% sure if I solved the 1st error / I might have introduced 2nd error in addition to 1st by adapting two changes)

Could not find module 'Lottie' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios-simulator

The second library that I am using is lottie-ios and I am pulling this in with a swift package manager. I guess what is happening is that because I excluded arm64 in build setting for iOS simulator, Xcode is attempting to run my app in x86_64. However, library is not supported running in x86_64 for some reason, and is throwing an error. I don't have much insights into what dictates whether or not library can run in x86_64 or arm64 so I couldn't dig to investigate this issue.

My weak conclusion is that GoogleWebRTC cannot be compiled to run in iOS simulator with arm64 for some reason (unlike what its doc says), and lottie-ios cannot be compiled to run in iOS simulator with x86_64. So I cannot use them both in this case.

Q1. I want to know what kind of changes I can make to resolve this issue...

The app compiles and runs perfectly in both device & simulator when compiled from Intel Mac. The app compiles and runs fine in device when compiled from Apple Silicon Mac. It is just that app refuse to be compiled and run in iOS simulator from Apple Silicon Mac, and I cannot seem to figure out why.

Q2. If there is no solution available, I want to understand why this is happening in the first place.

I really wish not to buy old Intel Mac again just to make things work in simulator.

Fidellia answered 31/1, 2021 at 11:4 Comment(2)
Running into a similar problem. Have you found a solution to the Could not find module 'X' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios-simulator problem?Encumber
I posted an answer. I hope that helps with the problem that you are having..Fidellia
F
65

Answering my own question in a hope to help others who are having similar problems. (and until a good answer is added from another user)

I found out that GoogleWebRTC actually requires its source to be compiled with x64 based on its source depo.

For builds targeting iOS devices, this should be set to either "arm" or "arm64", depending on the architecture of the device. For builds to run in the simulator, this should be set to "x64".

https://webrtc.github.io/webrtc-org/native-code/ios/

This must be why I was getting the following error.

building for iOS Simulator, but linking in dylib built for iOS, file '/Users/andy/workspace/app/Pods/GoogleWebRTC/Frameworks/frameworks/WebRTC.framework/WebRTC' for architecture arm64

Please correct me if I am wrong, but by default, it seems that Xcode running in Apple M1 silicon seems to launch iOS simulator with arm arch type. Since my app did run fine on simulators in Intel Mac, I did the following as a workaround for now.

  1. Quit Xcode.
  2. Go to Finder and open Application Folder.
  3. Right click on Xcode application, select Get Info
  4. In the "Xcode Info Window" check on Open using Rosetta.
  5. Open Xcode and try running again.

That was all I needed to do to make my app, which relies on a library that is not yet fully supported on arm simulator, work again. (I believe launching Xcode in Rosetta mode runs simulator in x86 as well..?? which explains why things are working after making the above change)

A lot of online sources (often posted before M1 Mac launch on Nov/2020) talks about "add arm64 to Excluded Architectures", but that solution seems to be only applicable to Intel Mac, and not M1 Mac, as I did not need to make that change to make things work again.

Of course, running Xcode in Rosetta mode is not a permanent solution, and Xcode slows down lil bit, but it is an interim solution that gets things going in case one of libraries that you are using is not runnable in arm64 simulator.. yet.

Fidellia answered 7/2, 2021 at 23:54 Comment(9)
So you are building an x86 app running on an x86 simulator on an ARM processor. I guess there will be more than one build script around that assumes the simulator runs on x86.Shephard
I found another workaround, without needing to use Rosetta. While my app does not run in a current iOS Simulator, it runs e.g. in iPhone 11 Pro (13.0). I am not sure, but I have the impression that this simulator does not use the arm64 architecture, while the iPhone 12 Pro Simulator or even iPhone 11 Pro (14.5) do. I wonder if this works for you as well?Lens
Thank you so much for this. Just stumbled on your answer and it saved me hours of head scratching lol.Forester
As mentioned above, a better solution is to setup your project to force the simulator to run as x86 and not all of Xcode. That allows Xcode to compile at full speed under Apple Silicon. Following article (not mine) explains this. blog.sudeium.com/2021/06/18/…Kucik
Switching to Rosetta is like the very very very last resort. I didn't get an M1 to emulate x86_64. Like said, basically I'm developing an ARM app (iOS) but emulating a complete x86 environment 0_oApparitor
can you put an screenshot from your settingsStricklin
It's not actually a solution for M1 machine. 1. Putting "arm64" into EXCLUDED_ARCHS basically builds evrth into x86_64 2. Running XCode in Rosetta launches the simulator in Rosetta (from ios 13.7 they have both arm64 and x64 simulators but nevertheless) As a result as mentioned above - you are compiling your code as x86_64 and run it on x86_64 simulator - on M1 machine which should 'natively' support arm64 code and run it inside arm64 simulator.Acreage
if we are speaking about workaround, @MichaelLong solution is a great improvemnt - XCode continues to run natively in that case.Acreage
The link to the article given in @MichaelLong 's comment worked for me. I am running Xcode on an M2 chip with cocoapod dependencies that don't support arm64. I had to set the Architectures (not exclude option, just gen Arch) for "Any iOS simulator SDK" to "x86_64" for EVERY Project/Module in my application. Also, it was important to make sure "Build Active Architecure Only" was set to "NO".Homemaker
K
19

I found the fix here thanks @Narlei

1- Set exclude arm64 architecture in your project

enter image description here

2- This at the end of your Podfile

post_install do |installer|
  installer.pods_project.build_configurations.each do |config|
    config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
  end
end
Keith answered 7/4, 2022 at 22:50 Comment(0)
H
4

I am running Xcode on a M2 silicon macbook. The app I'm building has mutiple modules that variably depend on cocoapods that are not configured to build on arm64-simulators, hence the error in question.

Running Xcode in Rosetta worked to get the app to build onto the Sim, but only for the first build, and everything ran much slower. When I would subsequently rebuild and run the app again, it would not attach the process to the Sim! I would get a black screen and spinning wheel of death on Xcode for "Launching app" which was quite annoying. I had to find a different solution, which I will explain below.

Following this link given by @Michael Long

https://blog.sudeium.com/2021/06/18/build-for-x86-simulator-on-apple-silicon-macs/

I had to set the "Architectures" (not exclude option, just general Arch) for "Any iOS simulator SDK" to "x86_64" for EVERY Project/Module in my application. Also, it was important to make sure "Build Active Architecure Only" was set to "NO". I then went to my podfile and added this:

        config.build_settings['ARCHS[sdk=iphonesimulator*]'] = 'x86_64'

to the post install part of the podfile. If you find that certain internal modules cannot be found during a build, you missed a build setting described above for that module.

Homemaker answered 2/12, 2022 at 19:16 Comment(0)
Z
3

Building for iOS Simulator, but linking in dylib built for iOS, file 'HyperSDK/HyperSDK.framework/HyperSDK' for architecture arm64.

if you face this error,

  1. open Xcode
  2. go to Product
  3. click on destination
  4. click on Destination architectures
  5. select show Rosetta destination

this will resolve the issue for building IOS Simulator

Zambia answered 27/4, 2023 at 10:49 Comment(0)
S
2

It is not supported by Apple to run Xcode simulator thru Rosetta. There are a lot of bugs.

It's much better to isolate problematic libraries thru Cocoapods and build them only to supported architectures.

post_install do |installer|  
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      # Targets that do not support m1 simulator
      if ['Lib1', 'Lib2'].include? target.name
        config.build_settings['ARCHS[sdk=iphonesimulator*]'] = 'x86_64'
      end
    end
  end
end

Then you can use #if to isolate code, that uses this frameworks.

#if !((arch(arm64)) && targetEnvironment(simulator))
// Not M1
#else
// M1
#endif

P.S. Here is how you can create pod with any framework.

Subchaser answered 21/12, 2021 at 12:39 Comment(0)
E
0

Quit Xcode. Go to Finder and open Application Folder. Right click on Xcode application, select Get Info In the "Xcode Info Window" check on Open using Rosetta. Open Xcode and try running again.enter image description here

Effuse answered 14/6, 2021 at 9:55 Comment(2)
You can do this, but a better solution is to setup your project to force the simulator to run as x86 and not all of Xcode. Following article (not mine) explains this. blog.sudeium.com/2021/06/18/…Kucik
no such option "Open using Rosetta"Insociable
H
0

I am not sure "exactly" what works, but... just using xattr -rc <path-to-executable> didn't work all the time. Instead, I ran all of the below 3 in a row:

  1. chmod +x <path-to-executable>
  2. chown <my-pc-user-name> <path-to-executable>
  3. xattr -rc <path-to-executable>
Harappa answered 17/1 at 15:44 Comment(0)
N
-1

Adding this line of code to my pod file resolved the issue for me:

config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
Nicolenicolea answered 25/8, 2023 at 17:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.