Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declare Podspec with a dependency to an objc library

I am developing a Swift framework (MyFramework) that has a dependency to a third party static library written in Objc (NewRelic)

I am using CocoaPods 1.4.0 and I have declared my podspec like this:

...

s.source_files = 'MyFrame/Classes/**/*'

s.static_framework = true
s.dependency    'NewRelicAgent', '6.1.1'     # Obj-c

s.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(PODS_ROOT)/NewRelicAgent/NewRelicAgent/NewRelicAgent.framework/Headers', 'SWIFT_INCLUDE_PATHS' => '$(PODS_TARGET_SRCROOT)/MyFrameFramework' }
s.preserve_paths = 'MyFrameFramework/MyFrame.modulemap'

From what I read in different posts, what I think I am doing here is:

  1. first declare a static_framework to be able to use a static library, NewRelic.
  2. Set the NewRelic dependency.
  3. Set the header paths to find the NewRelic headers and locate the modulemap as explained here

This is my MyFrame.modulemap:

framework module LGResources {
    umbrella header "MyFrameFramework.h"

    export *
    module * { export * }
}

And this MyFrameFramework.h:

//! Project version number for LGResources.
FOUNDATION_EXPORT double MyFrameVersionNumber;

//! Project version string for LGResources.
FOUNDATION_EXPORT const unsigned char MyFrameVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <Amplitude/PublicHeader.h>

#import <NewRelicAgent/NewRelic.h>

Inside my framework classes I am trying to use NewRelic but it does not work

enter image description here

I am starting to give up since I find confusing to have so many references in the CocoaPod specs: module_map, frameworks, vendored_frameworks, dependency, preserve_paths, ...

Can someone please point me into the right direction? How can I declare a static dependency and use it inside my framework?

Many thanks in advance!

PS: I don't really know where should I put the MyFrameFramework.h file to be managed by CocoaPods, by I have tried different manual approaches with no luck.

like image 348
Xavi Gil Avatar asked Mar 28 '18 21:03

Xavi Gil


People also ask

What is local Podspec?

A Podspec, or Spec, describes a version of a Pod library. We can use a local path to a directory on your computer and write a Podspec in that directory and use CocoaPods. This is called local podsec.


1 Answers

There may be additional issues, but one problem is that NewRelicAgent.framework is missing a module map.

Static frameworks can have other static frameworks or static vendored_frameworks as dependencies. A static library is not sufficient. A module map bundled into a framework is necessary to tell the build system how to access its public methods from Swift or Objective C modules.

The NewRelicAgent podspec is specifying a vendored_framework, but the zip is missing a module map.

It might be possible to come up with a workaround, but the best solution would be to convince the NewRelicAgent pod maintainers to update the pod.

like image 56
Paul Beusterien Avatar answered Sep 29 '22 12:09

Paul Beusterien