4

My iOS project depends on some CustomLib.framework. This framework comes as two separate files: one for simulator, another for real device.

I put these files into folders

@(PROJECT_DIR)/device_frameworks/CustomLib.framework

and

@(PROJECT_DIR)/simulator_frameworks/CustomLib.framework

I edited

Build Settings->Search paths->Framework search paths:

Any iOS Simulator SDK     $(PROJECT_DIR)/simulator_frameworks
Any iOS SDK               $(PROJECT_DIR)/device_frameworks

What I do not understand is how to add CustomLib.framework to the Xcode project, and how to add it as embedded framework (Build phases->Embed frameworks). Because on these steps I have to specify a concrete framework, but I have two separate frameworks in device_frameworks and simulator_frameworks folders.

2 Answers 2

5

There is no way in xcode to include them depending on architecture, but Apple introduced 2019 XCFrameworks as a new code distribution format.

From XCode 11 release notes:

An XCFramework makes it possible to bundle a binary framework or library for multiple platforms —including iOS devices, iOS simulators, and Mac Catalyst — into a single distributable .xcframework bundle that your developers can use within their own applications.

You can use this to bundle both of those frameworks into one, add that to your projects and Xcode uses the right platform’s version of the included framework or library at build time.

You can create an XCFramework from Terminal by using the following command:

xcodebuild -create-xcframework -framework PATH_TO_FRAMEWORK1 -framework PATH_TO_FRAMEWORK2 -output PATH_TO_BUNDLED_FRAMEWORK

Where PATH_TO_FRAMEWORK1 and PATH_TO_FRAMEWORK2 are the paths to your frameworks and PATH_TO_BUNDLED_FRAMEWORK is the path of the resulting XCFramework.

Assuming you're in your project dir, the command could look like this:

xcodebuild -create-xcframework -framework device_frameworks/CustomLib.framework -framework simulator_frameworks/CustomLib.framework -output BundledCustomLib.xcframework

Then you would only need to add BundledCustomLib.xcframework to your project.

2

It's simple, you may use variables in xcode *.pbxproj, someting like this:

        55C7DBBB27DA529E000E0A09 /* rutoken_splitter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = rutoken_splitter.framework; path = "../../../_result/$(BUILD_ARCHITECTURE)-$(SUPPORTED_PLATFORMS)$(RUNTIME_SUFFIX)/framework/rutoken_splitter.framework"; sourceTree = "<group>"; };

In my example I use variables BUILD_ARCHITECTURE, SUPPORTED_PLATFORMS and RUNTIME_SUFFIX. Simplest way is to set these variables via *.xcconfig

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.