iOS8 framework library linking WITHOUT Pods - ios

Imagine the following scenario;
I'm developing a cocoa touch framework that requires SomeLibrary (e.g. AFNetworking). My framework is going to be included into someone's project that might require SomeLibrary as well.
How do I accomplish this without running into these nasty duplicate warnings when I include AFNetworking into my framework directly (either via source code or Cocoapods)?
I've tried it with Cocoapods on both projects (my framework, and a test project that includes my framework), but that results in duplicate code warnings as well.
When I don't add AFNetworking into my framework development project, the compiler can't find the required files, which is why I can't build it. I've tried with including AFNetworking's source code directly into the main project, and using the pod, but in both cases the AFNetworking/AFNetworking.h import in the framework project fails.
How can I do this without making a pod out my framework (which isn't really an option)?
I've found this related answer, but I don't know what search path to set for the framework project in order to find a library of the master project;
https://stackoverflow.com/a/23123725/1069487
Any help would be highly appreciated!

You will have to build your framework linked against static library.
You build AFNetworking as a static library (that will give you a .a file as AFNetworking.a)
You build your framework that link against your static library. But be aware that the library won't be embedded in your framework (there is no way to include static library into framework on iOS). Your framework is able to use AFNetworking API because it is linked against it.
any project that use your framework and use AFNetworking methods of your framework need to link with the static library AFNetworking.a that you should provide as a standalone file beside your framework.
See iOS-Framework here for more details : https://github.com/jverkoey/iOS-Framework

Related

How to add a local framework to a Flutter plugin for iOS

So, I've been struggling for some time with embedding a third party framework into a Flutter plugin I'm writing for iOS.
The plugin is fairly straightforward, mostly just forwarding calls and events to/from the third party framework.
The third party framework in questions is for controlling a Sphero robot (RobotKit.framework).
This particular framework is an umbrella framework, with several sub frameworks within.
To include this .framework in my plugin, I've tried a lot of combinations between
preserve_paths
vendored_frameworks
resource
xcconfig
in the .podspec file to link to the RobotKit.framework package (inspired by blog), but without luck.
I can use
vendored_frameworks = 'Frameworks/RobotKit.framework'
to get Xcode to detect the package and import the headers, but when building I get an error linking to a header in one of the sub frameworks (RobotKitClassic is a sub framework):
fatal error: 'RobotKitClassic/RobotKitClassic.h' file not found #import <RobotKitClassic/RobotKitClassic.h>
Am i approaching this the wrong way, or is there a trick that I'm missing?
I ended up working around this by implementing the plugin functionality directly in my main app project instead of in a separate Flutter plugin.
Doing this, i can add the RobotKit framework to the Runner project and it links, builds and runs just fine.
IF your case is nested frameworks to use the result in app then nesting frameworks isn't allowed in IOS , here from apple forums , I faced error like can't load frameWork #rpath to do this all code in dynamic framework must be pure code not pods or plugins

iOS: Dynamic Framework based on static library dependency

I am working on creating a Dynamic Framework (Cocoa Touch Framework) that has to use a VideoKit lib as a core. Library is a .a file with a number of header files (about 20) and example ViewControllers in ObjC (you can grab demo SDK from: Link). In the future my Framework will be providing a player widget written in Swift (based on sources from ObjC and some other specific features) to DemoApp. But for now I cannot handle dependency in my Dynamic Framework in a proper way.
My first approach was to add the SDK to Framework project. I followed instructions provided
by a producer but instead of adding SDK to the App project I added it to the Dynamic Framework Project. There was no module map file and no Umbrella header for VideoKit library so I created them. The result was that some errors went away (related to Headers in the module). I also removed Controllers source files from compiled sources because I did not need them - I just wanted to run the core in the first place. I got stuck on errors saying that there are no symbols for various architectures (x86, arm64).
My second approach was based on what I read on SO and other resources. I moved the dependency to the App project. In the Dynamic Framework Build Settings I added paths to Headers and Library sources from VideoKit SDK that are now stored in the App Project. Again, I am stuck with ā€˛Undefined symbols for architectureā€¯ errors.
I would appreciate if someone can guide me what I am doing wrong - it is my first time when I have to build framework with dependency on static library and cannot use Dependency Managers to resolve it - actually it is my first time on building iOS Framework ever.
Here is a link to the repo with my actual work on this problem: Repo
I had to remove VideoKit SDK from project because of license restrictions. You have to download it and add it manually.

How to build an iOS Framework with a dependency on another without creating an Umbrella Framework

I am trying to streamline my development by creating some re-usable Frameworks which incorporate features I commonly re-use in multiple projects.
However, having setup one of my Frameworks I have encountered a problem, the classes have a dependency on the Firebase framework. Having read the Apple docs it's not recommended to create an Umbrella Framework (one which embeds another) especially if you do not have ownership of the embedded Framework (which I do not).
So the question is:
How can I create a Framework project which allows me to build the Framework without including the dependencies which would create an Umbrella Framework. I presume this is what people like Firebase do because when you add their Framework there are others you have to add to your project as well. I can't quite see how you would configure a project to allow you to build the Framework without errors but not include the dependencies.
For reference I am using the latest Xcode and need to support iOS 8 and above.
Thanks in advance for any thoughts / suggestions on this
For the benefit of anyone who is struggling with the same issue, the answer is much simpler than I had anticipated.
The Frameworks are linked dynamically and simply adding a Framework to the project for your own framework will not cause it to be embedded in the output file and therefore not generate an Umbrella Framework. You don't actually need to do anything. Any Frameworks that are required by your own Framework can be included in your project so that you can compile your own Framework, and will also need to be included in any projects that utilise your Framework.

Using code from framework without linking it

I am building a cocoa touch framework and including in my code third party framework - "framework_X"
How can i use it in a way that "framework_X" will not be linked directly to my framework, instead it will require the consumer project which use my framework to link "framework_X" to his project in order for it to work.
In Android this is done easily, but in Xcode if i am not linking the "framework_X" in my framework the project won't build
You can load libraries at runtime. Here an example of loading zlib with dlopen():
https://github.com/nicklockwood/GZIP/blob/master/GZIP/GZIP.m

iOS Framework build: what is the best practice to link with third-party libraries?

I'm build a Framework for iOS and my framework has AFNetworking as dependency.
So what is the best practice to include AFNetworing? Reading other posts (specially this question here) i came up with three options:
Copy all the .h.m files from AFNetworing in to my project and compile my framework with it. But according to this, it will possible cause a situation where some third part developer using my Framework are already using AFNetworking and will get a compile-time error that some class is declared twice.
Use CocoaPods and link AFNetworking to my Framework. This is causing this error: -lPods is not an object file (not allowed in a library).
Build something like the Aeris SDK where the third part developer using my Framework will be responsibly to add AFNetworking to their project.
I think that option 3 is the best but i don't know how to do that. How can i dev my framework calling AFNetworking classes/methods but do not include on the final framework product?
Thanks!
That's a very bad practice to use third party library in you library.
Ideally you should avoid doing that.
But if you really need it, you can define and add prefixes to class names.
Refer this article Avoiding dependency collisions in iOS static library managed by CocoaPods
Ok. I decided to go with the option 3.
A just added all the header files from any third-party lib to the my framework project (you can also add the .m files but not include them on the static library target).
And a i also documented everything, so developers using my framework will know what are the dependencies and how to include/install them on their own projects (including third-party lib versions, CocoaPods support, etc).
I decided not to go with option 1 because that will cause some situations where a project will have two copies of the same lib compiled on the final app. Even if a change the namespace for the libs on my framework code (to prevent "duplicated symbols" errors) that will still cause some other possible problems like an APP with larger size, possible bugs related to two or more instances of the same lib running together, etc...

Resources