10

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

HangarRash
  • 7,314
  • 5
  • 5
  • 32
Merrick Sapsford
  • 139
  • 1
  • 1
  • 8
  • What about if i have building a swift framework containing a other cocoapods ? . I did checkout your github repo and i can see that your OtherFramework.xcframework which is external framework contains both arm64 and x86_64 files in it. In my case when i do a pod install the three dependencies does not contain device support ?. Is this something xcode does it my itself ?. or i need to manually build my dependencies each of them for both device and sim and copy those into my swift project for it to build ? . Can you share a sample project with cocopods in it which builds ? – Max Oct 24 '20 at 06:00

6 Answers6

3

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

Merrick Sapsford
  • 139
  • 1
  • 1
  • 8
  • can you please share a github link to the solution you described above ? – Max Oct 23 '20 at 08:57
  • 2
    this issue is still persisting in xcode12.4 right? i am having the same issue and have to go this path to solve it – Martin Mlostek Feb 19 '21 at 16:31
  • Yup @MartinMlostek I'm having it also and this was indeed the fix. It seems XCode simply doesn't work well with xcframeworks, ironically. – BTRUE Jul 14 '21 at 21:37
1

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

Steven
  • 63
  • 5
  • The search paths are set correctly - both projects can individually find the `xcframework` without issue. The build errors occur when trying to link them both in a workspace, which is required to ensure the framework is embedded and linked correctly. – Merrick Sapsford Feb 05 '20 at 18:56
1

I had this issue as well after using xcframework instead of framework. So I changed my project structure:

The MyFramework Peoject embed OtherFramework.xcframework,Then make it exported using @_exported import OtherFramework in MyFramework Project. And the MyApp just link MyFramework but can both import/use MyFramework and OtherFramework.

BTW, It seems to custom the @rpath and manual codesign the OtherFramework.

Genki
  • 3,055
  • 2
  • 29
  • 42
1

IMO, It seems not xcframework issue.

Check out this answer: https://stackoverflow.com/a/59435627/2661407

Umbrella frameworks are not supported on iOS, watchOS, or tvOS.

OtherFramework.xcframework should be signed and embedded in your host app.

and add "@executable_path/Frameworks" setting into your MyFramework.framework > Build settings > Runpath Search Paths.

Bumseok
  • 971
  • 8
  • 6
  • None of the frameworks here are umbrella frameworks, the issue arises when trying to embed `OtherFramework.xcframework` in the host application while it is also linked in an another framework that the host app uses. – Merrick Sapsford May 17 '20 at 13:20
  • You are correct. It's not a umbrella framework issue. I also have same problem you experienced. Then I suggest a workaround. https://github.com/msaps/XCFramework-Link-Issue/pull/2 – Bumseok May 22 '20 at 08:27
0

I had an issue like that as well. First, make sure if you have MyFramework.framework file within the same directory as MyApp.

Second, when building MyFramework.framework, make sure that OtherFramework.xcframework is as well in MyFramework's project directory.

And one more thing, check target SDK versions. They should be somewhere on the same level.

Roman Bugaian
  • 354
  • 1
  • 7
  • 22
  • The `MyFramework` framework is a project within the workspace - they both have the same `$(SRCROOT)` and the framework search paths are set correctly. `OtherFramework.xcframework` can be found without an issue when it is linked only in one of the projects, but if I link it in both (and embed in `MyApp`), as required to properly include the framework, the build errors occur. – Merrick Sapsford Feb 05 '20 at 18:55
-1

I had the same issue as you, and after seeing your pbxproj I think it can be solved the same way.

Change your framework search path to recursive (either through UI or manually editing the pbxproj "$(SRCROOT)/../Frameworks" => "$(SRCROOT)/../Frameworks/**"), like so: https://github.com/msaps/XCFramework-Link-Issue/pull/1/files

  • The link you included in your answer may point useful information, if it does, you should include this information in your answer and refrain from posting link-only answers. If the link breaks in the future your answer will have no value. – Mustafa Apr 21 '20 at 15:29
  • @Mustafa The link points to a PR of a single line changes that is already in the answer in entirety. – dipidoo Apr 28 '20 at 17:04
  • @dipidoo having checked this out - it potentially can workaround the issue in some projects. But it also can cause issues where the incorrect architecture is attempted to be linked from the XCFramework. I've updated the [README](https://github.com/msaps/XCFramework-Link-Issue) to reflect this information. – Merrick Sapsford May 17 '20 at 13:15