how to correctly build an app for device and simulator that conditionally uses the correct framework. (not a universal/fat framework)

Viewed 425

Have obtained separate frameworks for device and simulator, and I want to integrate those frameworks to achieve the desired functionality. I have included the simulator framework in my carthage framework project. When I am compiling my framework, I am getting the following error

building for iOS-armv7 but attempting to link with file built for iOS-arm64 Undefined symbols for architecture armv7: "OBJCCLASS$...", referenced from: objc-class-ref in ViewController.o "OBJCCLASS$...", referenced from: objc-class-ref in DepedencyInjector.o objc-class-ref in ViewController.o ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

reference: https://developer.apple.com/forums/thread/66978 https://developer.apple.com/forums/thread/66978?answerId=215100022#215100022

2 Answers

If it is an option for you to link both of the frameworks together you can just let the compiler decide. In this case you create a FAT binary. This means:

  • you link both frameworks together
  • create one (FAT) framework
  • link this library to your app in Xcode
  • let the compiler decide about the correct architecture

The command to create a FAT binary is:

lipo -create ./Simulator.framework/framework_binary ./Device.framework/framework_binary -output ./Universal

Now you have to duplicate the folder Device.framework and name it Universal.framework.

Copy the binary created with lipo into this folder.

Then open the file ./Universal.framework/Info.plist and add the string iPhoneSimulator in the CFBundleSupportedPlatforms array.

Now copy x86_64.swiftdoc and x86_64.swiftmodule from the folder Simulator.framework/Modules/framework_name.swiftmodule/ and paste them to Universal.framework/Modules/framework_name.swiftmodule/.

Import the created universal framework into Xcode in your targets Embedded Binries section and you should be able to compiler your project.

You can build a XCFramework as follows (from the command line).

xcodebuild \
    -create-xcframework \
    -framework  "<<path to simulator xcarchive>>/Products/Library/Frameworks/SomeFramework.framework" \
    -framework  "<<path to device xcarchive>>/Products/Library/Frameworks/SomeFramework.framework" \
    -output     "CombinedFramework.xcframework"

You can add more to this and set the various paths and output to taste.

Not sure if this helps as you are not looking for universal frameworks and not sure how you classify this one ...

Related