How to load framework at runtime in Xcode?

633 Views Asked by At

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

2

There are 2 best solutions below

2
On

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.

0
On

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'