I have a fat iOS library which supports both real devices (arm64...) and iOS simulator of Intel Mac (x86_64). But when I switched to M1 mac, things get tough.
If I use the old library, I will fail with error saying xxx.a (xxx.o) building for iOS Simulator, but linking in object file built for iOS, file 'xxx' for architecture arm64
. It seems that I have to build a xcframework which contains binaries for different destinations.
So I tried to build different slices and hope to bundle them as a xcframework. But I finally found I don't know how to build the x86_64 slice with a M1 Mac.
My question is
actually i386 architecture is for iPhone simulator where as x86_64 architecture is for iPad simulators, both are 32 and 64bit compatible.
Both ios-arm64-simulator and ios-x86_64-simulator represent two equivalent library definitions. Seeing these when trying to create an xcframework for Apple Silicon that supports Mac Catalyst and the iOS Simulator: Both ios-arm64-simulator and ios-x86_64-simulator represent two equivalent library definitions.
To run a simulator on an M1-based Mac, your linked frameworks need to support an ARM64 for M1 slice. This is accomplished by application vendors shipping a new product packaged as an XCFramework rather than the traditional Framework. This new product version can include an M1 Simulator slice for testing.
When we run in M1 Macbooks we are unable to run on arm64 simulators and get the following error: Our SDK is built into an XCframework bundle, however this issue still persists.
We have tried building the static library into its own XCframework as well by separating the architectures into two different binaries, one for Device and one for Simulator, however we still didn't get it to work.
It’s possible to debug both slices of a universal binary on Apple silicon, but you must run the x86_64 slice under Rosetta translation. Xcode 12.2 and later is a requirement for building universal binaries. Earlier versions of Xcode don’t contain the support needed to build and test universal versions of your macOS code.
The reason I failed to get x86_64 slice on M1 Mac is that there is a legacy option in my build setting: Valid architectures.
Remove this configuration and run standard flow. Then you will get library containing x86_64 architecture smoothly.
xcodebuild archive --destination="generic/platform=iOS Simulator" ...
If your library code is not organized as a Xcode project but uses clang toolchain underneath. You can refer to this link. In a nutshell, specify target in a format like arm64-apple-ios14.3-simulator
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With