semenchikus
semenchikus

Reputation: 760

Build Swift dynamic framework with third party static framework as a single framework

Trying to prepare a single dynamic framework to my customer. My framework (A.framework) uses third-party recognition static framework (B.framework). I can't provide separate A and B frameworks to the customer. Ideally B.framework should be built and included into my A.framework's binary, so the customer's app will only embed A.framework without any additional actions to link with that third-party app.

What I did:

  1. Added B.framework to the project.
  2. Added B.framework to "Linked Frameworks and Libraries" in the corresponding target.
  3. Built A.framework.
  4. Created a demo application and included A.framework to the project.
  5. Added A.framework to "Embedded Binaries".
  6. Demo app's build fails with message "Missing required module 'B'" (despite the fact that it is used in A.framework only).

Note:

Any ideas would be highly appreciated!

UPD 1: This is not about umbrella framework because the proper umbrella framework implementation requires to load sub-framework from bundle which is not good. The fake framework implementation (sub-framework simply copied to umbrella) won't work for release because of different Mach-O values - dynamic and static. Plus fake umbrella framework has a huge size because sub-framework is being fully copied inside umbrella.

UPD 2: Created a small test project: StaticFrameworkTest which has 3 sub-projects:

  1. Demo-application with dynamic framework dependency (framework A) and shouldn't know anything about framework B
  2. Dynamic framework with static framework dependency (framework B) which ideally should be included in A framework's binary.
  3. Static framework B

Upvotes: 11

Views: 3184

Answers (1)

Gabriele
Gabriele

Reputation: 138

A static framework is by definition a fat static library combined with any additional required resources. As such you can embed your third party static library inside your own and also include images, storyboards, plist etc.

You can't do that in a static library (i.e. *.a), but in a static framework you can do. See for example https://www.raywenderlich.com/65964/create-a-framework-for-ios for details on how to do that (at the end of the article it creates the static *.framework out of the static *.a and some resources)

A dynamic framework can never embed a third party static library. The main application that imports the dynamic framework will always have to also explicitly link against the static library, which it seems that is not what you want.

Upvotes: 4

Related Questions