本文介绍了Xcode错误:“为iOS模拟器构建,但在为iOS建立的dylib中链接..为体系结构arm64",来自Apple Silicon M1 Mac的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,可以在具有物理设备和英特尔®处理器的较旧Mac上编译并正常运行.iOS模拟器.

同一应用程序还可以从带有M1处理器的最新Apple Silicon Mac(具有物理iPhone设备)编译并正常运行,但是,它拒绝为iOS模拟器进行编译.

如果没有模拟器支持,调试周转时间会变得很长,因此我正在尝试解决此问题.更不用说Xcode预览功能也不起作用了,这很烦人.

我没有进行任何更改(但从Intel Mac移到M1 Mac)遇到的第一个错误如下.

是为iOS Simulator构建的,但是在为iOS而构建的dylib中进行了链接,文件"/Users/andy/workspace/app/Pods/GoogleWebRTC/Frameworks/frameworks/WebRTC.framework/WebRTC"用于架构arm64

我正在使用的Cocoapods库是GoogleWebRTC,并且根据其文档,应支持arm64所以我很困惑为什么会引发上述错误.正如我之前所说的,我认为它可以在arm64上运行的真实设备中很好地编译.

根据文档.

我在线搜索了,此问题似乎有两种解决方法.

  1. 第一个方法是将 arm64 添加到 Excluded Architectures
  2. 第二个选项是将 Build Active Architecture Only 标记为 Release build.

即使我在以arm64架构运行的M1 Mac上编译我的应用程序时,我也不完全明白上述是否必要,因为该解决方案似乎仅适用于不支持arm64模拟器的Intel Mac,因为对于Intel Mac,模拟器可能已经在x86_64上运行,而不是在arm64上运行,因此解决方案#1在我的情况下不适用.

当我仅适应第二个更改时,什么都没有真正更改,并且引发了相同的错误.

当我同时进行更改和尝试构建时,现在在构建过程中出现以下第二个错误.(不是真的100%确定我是否解决了第一个错误/我可能会通过适应两个更改在第一个错误之外引入第二个错误)

找不到目标'x86_64-apple-ios-simulator'的模块'Lottie';找到了:arm64,arm64-apple-ios-simulator

我正在使用的第二个库是 lottie-ios ,我将其与快速的包裹管理器.我猜发生了什么事,因为我在iOS模拟器的构建设置中排除了 arm64 ,所以Xcode试图在 x86_64 中运行我的应用程序.但是,由于某些原因,不支持在 x86_64 中运行库,并且会引发错误.我对什么因素决定了库是否可以在x86_64或arm64中运行没有太多的了解,因此我无法深入研究这个问题.

我的弱结论是,出于某些原因(与说),并且 lottie-ios 无法编译为在 x86_64 的iOS模拟器中运行.因此,在这种情况下,我不能同时使用它们.

Q1.我想知道我可以做出什么样的更改来解决此问题...

该应用程序可以在设备&两种设备上编译并完美运行从Intel Mac编译时生成的模拟器.从Apple Silicon Mac编译后,该应用程序可以在设备上编译并正常运行.只是该应用程序拒绝在Apple Silicon Mac的iOS模拟器中进行编译和运行,而我似乎无法弄清原因.

Q2.如果没有可用的解决方案,我想了解为什么会首先发生这种情况.

我真的不希望仅仅为了使模拟器中的功能再次购买旧的Intel Mac.

解决方案

回答我自己的问题,希望对遇到类似问题的其他人有所帮助.(直到添加了其他用户的良好答案为止)

我发现GoogleWebRTC实际上要求根据其源代码仓库用 x64 编译其源代码.

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

这一定是为什么我遇到以下错误.

是为iOS Simulator构建的,但是在为iOS而构建的dylib中进行了链接,文件"/Users/andy/workspace/app/Pods/GoogleWebRTC/Frameworks/frameworks/WebRTC.framework/WebRTC"用于架构arm64

如果我错了,请纠正我,但是默认情况下,运行在Apple M1芯片上的Xcode似乎会以 arm 拱门类型启动iOS模拟器.由于我的应用程序在Intel Mac的模拟器上运行良好,因此,我暂时采取以下措施.

  1. 退出Xcode.
  2. 转到Finder并打开应用程序文件夹".
  3. 右键单击Xco​​de应用程序,选择获取信息
  4. 在"Xcode信息窗口"中检查使用Rosetta打开.
  5. 打开Xcode并尝试再次运行.

这是我需要做的所有事情,以使我的应用程序重新运行,该应用程序依赖于尚未完全受手臂模拟器支持的库.(我相信以Rosetta模式启动Xcode也会在x86中运行模拟器.

许多在线资源(通常发布于M1 Mac在2020年11月发布之前)都在谈论将arm64添加到 Excluded Architectures ",但是该解决方案似乎仅适用于Intel Mac,而不是M1 Mac,因为我无需进行更改即可恢复正常工作.

当然,在Rosetta模式下运行Xcode并不是永久性的解决方案,并且Xcode会减慢lil位,但是它是一种临时解决方案,以防万一您使用的库之一无法在arm64仿真器中运行.....

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 refuse 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..

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.

解决方案

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.

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.

这篇关于Xcode错误:“为iOS模拟器构建,但在为iOS建立的dylib中链接..为体系结构arm64",来自Apple Silicon M1 Mac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 00:45