iOS Static Library + CocoaPods and the duplicate symbols error

两盒软妹~` 提交于 2019-11-29 22:32:52

问题


I'm developing an Static Library / iOS Framework (Jeff Verkoeyen way) and I've added CocoaPods for manage dependencies (this is the big difference with other questions about duplicate symbols).

I've been struggling with the "duplicate symbols" problem when a client that use CocoaPods use my static library / framework and a 3rd party library that I'm using too.

I've been reading answers talking about not including 3rd party libraries into a custom static library but I want to do it this way, so that is not an option.

I've found this article (thank you Ryan Arana) that talks about this problem and "the best" solution and I've had to adapt it to my CocoaPods driven Static Library:

1. Create an empty NamespacedDependencies.h in the root of workspace and add it to main project.

2. Add this to the prefix header of the main project (before any include of pods):

    #import "NamespacedDependencies.h"

3. Add this hook to Podfile:

    post_install do | installer |

      environment_header = installer.config.project_pods_root + 'Pods-environment.h'
      text = "#import \"NamespacedDependencies.h\"\n\n" + environment_header.read
      environment_header.open('w') { |file| file.write(text) }

      dummy_class = installer.config.project_pods_root + 'Pods-dummy.m'
      text = "#import \"NamespacedDependencies.h\"\n\n" + dummy_class.read
      dummy_class.open('w') { |file| file.write(text) }

    end

4. Copy Ryan Arana's script to the root and edit the variables.

5. Add a "Run Script Build Phase" to Pods Target with:

    ./generate_namespace_header.sh

6. Build workspace. At this point I have my NamespacedDependencies.h macros.

7. Comment or remove the "Run Script Build Phase" that It has been created before.

8. Build again.

Problems: It works but it has problems:

1. Require manual steps. When I add/remove a pod to/from Podfile (and run pod install) I've to clean workspace (iphoneos and iphonesimulator in my case), left NamespacedDependencies.h empty, add the "Run Script Build Phase" (its removed by cocoapods) and start again.

2. I don't know if the post_install hook is ok, I just copied code from somewhere and change it but I'm sure that must be a better way to do this. I can't find documentation about it.

Edited:

  • I'm using CocoaPods 0.29.0, Xcode 5 and iOS 7
  • Ryan Arana's script is a slightly modification of the Nimbus' script. The "original" featherless's answer help me a lot. (See Ryan Arana's article)
  • When I run "pod install", the "Run Script Build Phase" and the NamespacedDependencies.h includes are deleted. This is why I've to create that phase every time I add/remove a pod, and why I've added a hook to add includes.
  • I add the import to Pods-environment.h because it's imported in the prefix header of each pod. But that configuration could change in future versions so I would like to find another way to do this. I don't know how to add it to each pch anyway. "General" Pod target has no pch so I've to add it to Pods-dummy.m directly.
  • If I don't comment or remove the "Run Script Build Phase" when NamespacedDependencies.h macros and libPods.a are already created, macros is recreated for the prefixed symbols and everything goes wrong.

来源:https://stackoverflow.com/questions/22540286/ios-static-library-cocoapods-and-the-duplicate-symbols-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!