iOS include third-party static library in Swift dynamic framework

Hello Swift experts!

I went here from the following discussion on Apple dev forum: Using dynamic framework which is l… | Apple Developer Forums

Briefly:

  • My dynamic (Cocoa Touch) framework uses third-party static library (Objective C) and I need to provide my framework to clients within this third-party dependency inside the framework
  • I Iink static library with my framework, include the headers and add modulemap file
  • Everything compiles on my machine, but when I try to build iOS app which embeds my dynamic framework, the project doesn't compile with error "Missing required module X" (X is that third-party static library).

What I've tried:

  1. Wrap static library in static framework and link this framework with my dynamic framework - same error.
  2. Same as step 1, but copy static framework inside my framework (and setup "Framework search paths" in iOS application) - Mach-O error while trying to export archived application.
  3. Not recommended umbrella framework - problems with loading static library from bundle inside umbrella framework.
1 Like

I've tried that tons of times. I guess the answer is 'No'.

If anyone had any solution of this I would appreciate that.

At last, I had to embed the static library inside my main target. It only works in that way.

@Leacode, thanks for reply! Finally I solved it: implemented static framework (with third-party library inside) and created .bundle file (iOS target) with all resources - storyboards, images, etc. Solution is not perfect, but works fine and I'm able to export the build.

1 Like

@semenchikus That's an interesting way of thinking. Of course a bundle can be used for packing and output assets. And thank you for letting me know at least I can do it like this.:blush:

I'm also having this exact problem and it's driving me nuts. Sadly, none of the above solutions helped. If anyone can have a look, here's a sample project exhibiting the problem.

Any help will be greatly appreciated.

Hi Sergiu,

Have you tried my final solution? It should work if configured properly. I don't see any bundles within resources and static inner framework inside dynamic in your sample proj.

Sorry Simon, but I couldn't fully grasp that solution as in my case I don't have any resources. Could you elaborate a bit, or even adapt it in your own fork, that would be grand.

Unfortunately, I don't have a time to prepare an example solution for you. You can do it yourself. If you don't have any resources, you can simply use static framework (mach-o parameter=static) inside your dynamic framework. Should be pretty easy to configure.

I tried with switching the Mach-O to static, and still the same problem. I've updated the project README with more details of the problem. No worries about the time, I understand. Will keep trying.

Easiest solution will be making your framework A static, so framework B will be sitting inside A as a resource. In the result I came to the same solution because it was too non-trivial to resolve these issues for dynamic umbrella framework (required a lot of scripting). If that's not allowed, wrap framework B in a bundle and use this bundle within dynamic framework A in your target ios application.

As a resource.. Is that possible for binaries? I think I'm too vague into the subject to even try anything. Thanks for explaining anyway.

Didn't understand what you've meant by binaries. Do you want to include some binaries into resource? Or you want to include the resource into binary?
As I said, you can simply make both frameworks static and include one framework into another without any problems. Do not bother with resources if no need.

By binary I mean the framework compiled code itself. Exactly, I would think it should be simple enough to include one into the other (and that's what I seem to have done in my sample project), but I have the error in the original post. (Sorry if we're going around in circles on this)

If you will make both of them static, you won't need to deal with resources.
Yes, you can include binaries into bundle, look at documentation. Bundles are widely used in Mac OS development.
Apple don't allow dynamic umbrella frameworks officially. So anyway it will be kinda "hack".

I guess, ObjC static library is fairly the same as Swift static framework. Have you tried to include Swift dynamic framework into another one?

I have a dynamic framework linking to multiple static frameworks, and the single dynamic framework embedded in my app. I’m also able to import the dynamic framework module, then get and use all the statically linked symbols by doing that.

How you may ask?
3 things...

  1. The dynamic framework “Other Linker Flags” needs -ObjC
  2. The dynamic framework needs “Single Object Pre-Link” set to YES
  3. The dynamic framework’s umbrella header imports all the statically linked framework modules. Which allows only importing the dynamic module to get all the statically linked modules.
1 Like

I have another issue when I include lib.a file in my dynamic framework, Xcode throws "undefined symbols"(these symbols appear in lib.a) errors. (If I change the Mach-O type to static, these errors will gone)

Could you give some advice? thanks.

My Framework looks like this:
---Some.framework(Dynamic Library)
------lib.a
lib.a is fat file, support all platforms(arm64, i386, etc.).

lib.a is fat file, support all platforms(arm64, i386, etc.).

I’m not really following this thread but the above is a concern. Fat libraries support multiple architectures for the same platform. There’s no Apple platform that supports both 64-bit Arm and 32-bit Intel. If you’re targeting iOS then you’ve fallen into the trap of assuming that iOS and the iOS Simulator are the same platform, which is not the case.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

Thanks for your apply,
sorry about the wrong description, the "platforms" I mean iDevices and Simulators.
Do you think is possible to include a static library in a dynamic framework?

If you are able to include a dependent framework to another framework target, can you please take a look my issue, I face an issue about that How can I include my dependent framework’s objects to my framework