19

I'm building a cocoapod that basically contains a framework (private sources) and a view (open source) that rely on this framework, all made in Objective-C.

In the podspec I have the following lines :

spec.vendored_frameworks = 'MyPod/Framework/MyFramework.framework'
spec.source_files = ['MyPod/UI/Views/MyView.{h,m}']

When using the use_frameworks! syntax, I can't #import MyFramework

I just don't understand what's happening.

Moreover, when I remove the spec.source_files line, I can #import MyFramework and it works perfectly, but of course I cannot use MyView.

What am I doing wrong ?

4 Answers 4

6

For anyone coming across this problem today: this is a known problem in CocoaPods, with a few issues raised on Github here and here discussing the problem.

The suggested workaround is to split your podspec into two: one podspec with only your vendored_frameworks and another podspec with only the source_files that use the framework.

User crsantos on Github has helpfully posted an example of this workaround, with two separate podspecs that I have reproduced below.

Vendored framework podspec:

# Regarding https://github.com/CocoaPods/CocoaPods/issues/6409
Pod::Spec.new do |s|
  s.name             = 'SampleDynamicLibPod'
  s.version          = '0.0.1'
  s.summary          = 'SampleDynamicLibPod. Cool Story bro!'

  s.description      = <<-DESC
Blah Blah Blah Blah Blah description
                       DESC

  s.homepage         = 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'Carlos Santos' => '[email protected]' }
  s.source           = { :git => 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource.git', :tag => "#{s.name}-#{s.version.to_s}" }
  # this is the way of tagging diferent podspecs on the same repo
  # Dont't forget to tag your repo with `SampleDynamicLibPod-0.0.1` for this specific spec

  s.module_name      = 'SampleDynamicLibPod'

  s.ios.deployment_target = '9.0'
  s.platform = :ios, '9.0'
  s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3' }

  s.vendored_frameworks = 'SampleDynamicLibPod/Frameworks/SampleDynamicLib.framework'
end

Source files podspec. Note the dependency on the vendored framework podspec.

# Regarding https://github.com/CocoaPods/CocoaPods/issues/6409

Pod::Spec.new do |s|
  s.name             = 'WrapperAroundSampleDynamicLibPod'
  s.version          = '0.0.2' # just a different number to avoid confusion with the other podspec
  s.summary          = 'WrapperAroundSampleDynamicLibPod. Cool Story bro!'

  s.description      = <<-DESC
Wrapper Around Sample Dynamic Lib Pod Blah Blah Blah Blah Blah Blah Blah Blah
                       DESC

  s.homepage         = 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'Carlos Santos' => '[email protected]' }
  s.source           = { :git => 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource.git', :tag => "#{s.name}-#{s.version.to_s}" }

  # Dont't forget to tag your repo with `WrapperAroundSampleDynamicLibPod-0.0.2` for this specific spec

  s.module_name      = 'WrapperAroundSampleDynamicLibPod'

  s.ios.deployment_target = '9.0'
  s.platform = :ios, '9.0'
  s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3' }

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

  s.dependency 'CocoaLumberjack/Swift'
  s.dependency 'SampleDynamicLibPod', '0.0.1' # you can achieve this with "#{s.name}-#{s.version.to_s}" from the 
end
Sign up to request clarification or add additional context in comments.

1 Comment

This answer solved my problem. Adding some keywords that might help others: react-native, expo, native-module. It's not a react-native or expo issue, but for those who are trying to use a vendored_framework in an expo native module, this should come in handy. Also, be sure your framework doesn't get picked up by an wildcards in your source_files.
1

If you use use_frameworks! your pod itself will become a framework. Therefore you should #import MyPod instead of #import MyFramework and then use MyView.

Review also public_header_files in case you need it.

3 Comments

Yes, but then, how do I access to MyFrameworks classes ?
Like you said, the MyFramework depencency is private. How do you want to access it from outside the pod? You said you only want to expose MyView to be open and this one relies on public headers from MyFramework. (By the way review your framework headers to make sure you allow access to it).
Only the sources of MyFramework are private. Moreover, I already access them without any trouble when not using use_frameworks!
1

While shocking's answer is technically right there is a way to combine source_files and vendored_frameworks. The solution is to also use preserve_paths pointing to the location of the vendored frameworks.

Comments

0

Since the project's pods are now a framework, you could try importing it as a module using @importMyFramework.

However, if that doesn't work, then try backing up your project and then running pod deintegrate && pod install. Also, this question is very similar, and some of its comments and answers may be helpful.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.