How to build an iOS framework with weak-linked Coc

2020-06-02 05:30发布

问题:

I am trying to build an iOS Framework (Test.framework) using the new template offered by Xcode 6 for creating Cocoa Touch Frameworks. The framework has different dependencies (as AFNetworking or FacebookSDK) specified in a Podfile. I don't want dependencies to be included in the framework, I just want to link against them.

The problem is that when I build the framework, the libPods.a is linked and included. Q: How can I link against libPods.a library, but not include it in the framework?


More details:

I have read about weak linking: https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html But I don't have much experience playing with project settings, so I'm a not a pro.

I tried to put libPods.a as an "Optional" but nothing changed, dependencies were still included.

I tried to remove the libPods.a from the section "Link Binary With Libraries" in Build Phases, but I get this error (after cleaning project folder and building again):

ld: library not found for -lPods-MyFramework-AFNetworking

I tried to remove all the flags from "Other Linker Flags", but it gives me undefined symbols:

Undefined symbols for architecture armv7:
  "_OBJC_CLASS_$_FBSession", referenced from:
      objc-class-ref in TestClass.o
ld: symbol(s) not found for architecture armv7

Here is the source code for a clean project with libraries included: https://www.dropbox.com/sh/0ymuzw6kiagz02j/AABzyHiZVaQQvBEnjBgRBq3ua?dl=0

回答1:

I can not comment yet so I will answer here. I think you can not do that. Cocoapods create a static library not a dynamic one so all the code should be there when you compile and is embedded in your framework.

Cocoapods documentation, go to "What is happening behind the scenes?" for a detail explanation

If you want to put together some basic configuration for some of your usual pods probably the best way to go is making a custom cocoapod with the other ones as dependencies. That way you can rely in cocoapods to manage versions and have the code updated per your preferences. I am using a similar approach myself and I am quite happy with the results.