2

I am facing problem while making universal frameworks in xcode 12. following is the command that i ran:-

lipo -create build/simulator/FrameworkName.framework/FrameworkName build/devices/FrameworkName.framework/FrameworkName -output build/universal/FrameworkName.framework/FrameworkName

And following is the error that i am facing:-

fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: build/simulator/FrameworkName.framework/FrameworkName and build/devices/FrameworkName.framework/FrameworkName have the same architectures (arm64) and can't be in the same fat output file

when i googled this error i found solution to set my 'Architectures', in 'Build Settings', to Standard, however it was already set to standard find the screenshot attached

Architectures Screenshot

Note: I was following this tutorial:- https://medium.com/@anuragajwani/how-to-build-universal-ios-frameworks-74b6b07bf31d

Ali Mehdi
  • 255
  • 5
  • 9

1 Answers1

2

The error tells you that both your frameworks in build/simulator and build/device folders have been built for the same architecture (arm64, which is a device architecture). You can verify this by yourself, by looking inside the .framework file: FrameworkName.framework/Modules/FrameworkName.swiftmodule. It is possible, that one of the folders (or both) contain more than one architecture like this: enter image description here

Personally, I like to build my 'fat' frameworks outside the Xcode.app folders (just to make sure I have complete control over what is where). First, run your framework for simulator (select any simulator as build target). After the process has completed, go to Products folder in Xcode Navigator, click Show in Finder on FrameworkName.framework file. Copy the shown .framework somewhere more convenient (e.g. Desktop/simulator folder) enter image description here

Then, build the framework again, only this time for device (select Any iOS device as build target). Copy second .framework somewhere like Desktop/iphone folder. Create empty Desktop/universal folder for output framework. Copy .framework file there from Desktop/iphone folder and remove Desktop/universal/FrameworkName.framework/Framework executable file. This file will later be replaced by lipo.

Next, do the lipo magic:

lipo -create ~/Desktop/iphone/FrameworkName.framework/FrameworkName ~/Desktop/simulator/FrameworkName.framework/FrameworkName -output ~/Desktop/universal/FrameworkName.framework/FrameworkName

Last step, go to Desktop/simulator/FrameworkName.framework/Modules/FrameworkName.swiftmodule copy all files that start with x86_64 prefix, and paste them to Desktop/universal/FrameworkName.framework/Modules/FrameworkName.swiftmodule. Now your Desktop/universal/FrameworkName.framework contains both device and simulator architectures. Congrats, you've got your 'fat' library!

Disclaimer: Yes, I realise there are easier ways to do this with various scripts and terminal commands, but all of them do pretty much the same thing. Once you try to do this manually step by step, it will help you understand what goes where, and what are architectures and how they can be combined.

Disclaimer 2: Starting from Xcode 12, Apple insists you build .xcframeworks instead of 'fat' libraries. See here

roxanneM
  • 853
  • 1
  • 7
  • 12
  • Thank you for the answer, Can you share with me any tutorial to create xcframeworks for my framework project? Actually, I have a framework project that uses third-party libraries via pods. When I try to make xcframework of my project and add in my demo app, the application crashes saying it can't find reference of my pod frameworks that I added in my framework application – Ali Mehdi Feb 27 '21 at 10:30
  • How to build a .xcframework: https://medium.com/swlh/how-to-build-xcframework-with-xcode-b3d0b3c08f43. As for the pods error, this issue is outside the scope of this question. Try referencing this to help you: https://medium.com/@akfreas/how-to-use-cocoapods-with-your-internal-ios-frameworks-192aa472f64b – roxanneM Mar 01 '21 at 11:41