Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 12.3: Building for iOS Simulator, but the linked and embedded framework was built for iOS + iOS Simulator [duplicate]

Tags:

ios

xcode12

lipo

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?

like image 980
spassas Avatar asked Oct 09 '22 13:10

spassas


People also ask

Do I need Xcode for iOS simulator?

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.

How do I change generic iOS device to simulator Xcode?

Open Xcode, Goto Preferences, Select Component. Click on Simulators of your choice then it will start the process of download & installing the simulators.

Is iOS simulator arm64?

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.


2 Answers

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

like image 74
Alex Shubin Avatar answered Oct 12 '22 02:10

Alex Shubin


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.

enter image description here

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

like image 37
Srikanth Avatar answered Oct 12 '22 03:10

Srikanth