Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding XCFramework in application with project framework dependencies

I have an Xcode workspace which features a project with an iOS Application target, and another project with a Framework target. The framework target is dependent on another framework, which is integrated in the form of an xcframework:

  • MyApp
  • MyFramework
  • OtherFramework

Using regular OtherFramework.framework would require it to be linked to MyFramework and then embedded in MyApp even though MyApp doesn't require the framework itself. However when integrating with xcframework, this project then fails to build with a No such module 'OtherFramework' error.

Project settings:

MyFramework Project

MyApp Project

Removing OtherFramework.xcframework from the MyApp target fixes the build issue, but then causes library not loaded errors as the framework is not present in the application.

Demo project here: https://github.com/msaps/XCFramework-Link-Issue

How are you meant to link an xcframework in an application and link in a dependent framework?

Why?

pyckamil just posted this article which explains the issue in detail: Everything wrong with XCFrameworks.

It turns out Xcode has an optimisation for the ProcessXCFrameworkLibrary step which extracts the correct .framework from an .xcframework for the active build architecture. This is only run once which causes issues for additional targets that try to link the same framework.

Update

This issue is resolved in Xcode 12.0

like image 982
Merrick Sapsford Avatar asked Feb 05 '20 14:02

Merrick Sapsford


Video Answer


2 Answers

UPDATED - Resolved in Xcode 12.0

shinsuk came up with a reliable workaround that works by adding architecture-explicit framework search paths to ensure the correct .framework within an XCFramework is found.

Details can be found in the README.

Search Paths

like image 66
Merrick Sapsford Avatar answered Oct 20 '22 11:10

Merrick Sapsford


Check build settings and defining the Framework Search Paths to a folder which contains the frameworks in question. If the frameworks are placed in your project directory, simply set the framework search path to $(SRCROOT) and set it to recursive.

check the response Getting error "No such module" using Xcode, but the framework is there

like image 1
Steven Avatar answered Oct 20 '22 09:10

Steven