I have written the below commands in a script file to create XCFrameworks for both iPhoneSimulator and iPhoneOS like this below:
xcodebuild archive -scheme "ProjectD" -archivePath "/Users/Ron/Archives/ProjectDiphoneSimulator.xcarchive" -sdk 'iphonesimulator' SKIP_INSTALL=NO
xcodebuild archive -scheme "ProjectD" -archivePath "/Users/Ron/Archives/ProjectDiphoneOS.xcarchive" -sdk 'iphoneos' SKIP_INSTALL=NO
xcodebuild -create-xcframework -framework "/Users/Ron/Archives/ProjectDiphoneSimulator.xcarchive/Products/Library/Frameworks/ProjectDiphoneSimulator.framework" -output "/Users/Ron/XCFrameworks/ProjectDiphoneSimulator.xcframework"
xcodebuild -create-xcframework -framework "/Users/Ron/Archives/ProjectDiphoneOS.xcarchive/Products/Library/Frameworks/ProjectDiphoneOS.framework" -output "/Users/Ron/XCFrameworks/ProjectDiphoneOS.xcframework"
I tried to use this in a project after dragging and dropping it onto the Embedded Frameworks and Libraries
When I run the project with a device as the target, it works fine. But when I run it on a simulator, it throws the below error:
While building for iOS Simulator, no library was found in /Users/Ron/XCFrameworks/ProjectD.xcframework
If I change the order of the archive and XCFramework creation like below:
xcodebuild archive -scheme "ProjectD" -archivePath "/Users/Ron/Archives/ProjectDiphoneOS.xcarchive" -sdk 'iphoneos' SKIP_INSTALL=NO
xcodebuild archive -scheme "ProjectD" -archivePath "/Users/Ron/Archives/ProjectDiphoneSimulator.xcarchive" -sdk 'iphonesimulator' SKIP_INSTALL=NO
xcodebuild -create-xcframework -framework "/Users/Ron/Archives/ProjectDiphoneOS.xcarchive/Products/Library/Frameworks/ProjectDiphoneOS.framework" -output "/Users/Ron/XCFrameworks/ProjectDiphoneOS.xcframework"
xcodebuild -create-xcframework -framework "/Users/Ron/Archives/ProjectDiphoneSimulator.xcarchive/Products/Library/Frameworks/ProjectDiphoneSimulator.framework" -output "/Users/Ron/XCFrameworks/ProjectDiphoneSimulator.xcframework"
It works for simulator and not on the device with the same error:
While building for iPhone, no library was found in /Users/Ron/XCFrameworks/ProjectD.xcframework
I have set the Build Libraries for Distribution to Yes as well. If I try to create them with different destinations(2 XCFrameworks for iphone and simulator) it is working. But that literally defeats the purpose of XCFrameworks.
Am I missing something or doing any of the steps wrong? Thanks for the answers in advance.