I have an app using a linked and embedded custom framework. The app built properly for iOS devices and simulators until Xcode 12.2. Starting from Xcode 12.3 however, I'm getting the following error:
Building for iOS Simulator, but the linked and embedded framework 'My.framework' was built for iOS + iOS Simulator.
The framework is built for both devices and simulators (as the error actually says) and merged using lipo
, so it should be able to run everywhere without issues.
Am I missing something here? Is there a relevant change in Xcode 12.3?
The Simulator app requires several other large directories from the Xcode distribution in order to work at all. The only official way to install all of those properly is to install the entire SDK from the dmg.
Open Xcode, Goto Preferences, Select Component. Click on Simulators of your choice then it will start the process of download & installing the simulators.
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.
I'm afraid that this is actually the correct error and the framework shouldn't contain iOS and iOS Simulator code at the same time. Apple tries to force us to use XCFramework
s for this purpose. They started it in Xcode 11 and just tightened up the restrictions.
The only correct way to resolve this is to rebuild the framework as an XCFramework. Which is easy to do:
xcrun xcodebuild -create-xcframework \
-framework /path/to/ios.framework \
-framework /path/to/sim.framework \
-output combined.xcframework
You can start with a combined .framework
. Make two copies of the framework, and use lipo
to remove the slices from the binary that are associated with a different SDK.
It is based on the original answer from Apple here.
My particular case is that I'm getting this error using Rome, which produces these frameworks (a possible solution is here). Also, a lot of struggling is going on on the Carthage side.
You have to exclude device architectures while building for simulator and while building for the device you have to exclude simulator's architectures.
To do that, navigate to Build Settings
of your project -> Excluded Architectures
-> Select the configuration(Debug/Release/Etc...) -> Tap + -> Any iOS Simulator SDK
-> Add arm64
, arm64e
, armv7
Similarly, add x86_64
, i386
to Any iOS SDK
.
PS: You can check all the architectures which are present in your framework by running file <path_to_framework_binary>
or lipo -info <path_to_framework_binary>
.
Ex. file /Users/srikanth.kv/MyProject/MyLibrary.framework/MyLibrary
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