1

I have a third party framework customx.framework (iOS) customx.framework (Simulator).

To run project on simulator customx.framework (Simulator) to be imported & for device customx.framework (iOS) to be imported

simultaneously importing is not supported by xcode

At present i am manually importing framework, so i am looking for runtime scrip changes or combined (iOS+Simulator) framework to import in xcode project.

For that

  1. I have tried lipo & libtool but seems didn't worked.
  2. I used validate workspace but it fails when importing modules.

tried links -

iOS merge several framework into one

Building for iOS Simulator, but the linked framework '****.framework' was built for iOS

Jack
  • 13,571
  • 6
  • 76
  • 98
  • 1
    A Swift Package might be what you are looking for. you have much more control. – lorem ipsum May 18 '22 at 12:14
  • @loremipsum any more hint please ? – Jack May 18 '22 at 12:29
  • 1
    I don't have an exact sample but I'll post some links that helped me figure it out before. I don't do this often, but I know it took me a while to figure out your `framework` has to become an [XCFramework](https://developer.apple.com/wwdc19/416) and then `XCFramework` can be used with [Swift Package Manager](https://developer.apple.com/wwdc19/408) the process isn't as straightforward as you would think. Once you get a package going it is really easy to manage. There are other WWDC videos on the topic. I wish I could be more specific. – lorem ipsum May 18 '22 at 13:08

2 Answers2

2

simultaneously importing is not supported by Xcode

Supported. It is named XCFramework.

So assuming each variant of frameworks have been built correctly (pay attention that BUILD_LIBRARY_FOR_DISTRIBUTION=YES, just in case - Xcode set it to YES automatically), join them in terminal or Xcode script phase with next command:

$ xcodebuild -create-xcframework 
      -framework "/full_path_to_iOS_variant/customx.framework" 
      -framework "/full_path_to_Simulator_variant/customx.framework" 
      -output "/full_path_to_result/customx.xcframework"

and then add it once in target dependency

demo

and that's it.

Asperi
  • 228,894
  • 20
  • 464
  • 690
  • It's Helpful. But i have readymade framework(No source code access) so when i run command i get error like .. `No swift interface file found within framework` @Asperi – Jack May 19 '22 at 05:48
  • Ok, not sure how you get that and why swift is there, but actually you can construct this wrapping XCFramework manually, it is only a bundle around existing frameworks with some info in plist. This article should be helpful https://appspector.com/blog/xcframeworks. – Asperi May 19 '22 at 06:07
1

You can archive for iOS device and iOS simulator and merge them to one xcframework. This is my current project xcodebuild command for it.

- Archive for iOS devices
xcodebuild archive \
-scheme Framework-scheme \
-configuration Release \
-destination 'generic/platform=iOS' \
-archivePath './build/native/Framework-Name.framework-iphoneos.xcarchive' \
SKIP_INSTALL=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES


- Archive for iOS simulator
xcodebuild archive \
-scheme Framework-scheme \
-configuration Release \
-destination 'generic/platform=iOS Simulator' \
-archivePath './build/native/Framework-Name.framework-iphonesimulator.xcarchive' \
SKIP_INSTALL=NO \
BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

- build framework from archives
xcodebuild -create-xcframework \
-framework './build/native/AdTrue-Native.framework-iphoneos.xcarchive/Products/Library/Frameworks/Framework-Name.framework' \
-framework './build/native/AdTrue-Native.framework-iphonesimulator.xcarchive/Products/Library/Frameworks/Framework-Name.framework' \
-output './build/native/Framework-Name.xcframework'
Mai Quân Nguyễn
  • 369
  • 1
  • 3
  • 5