I am trying to declare a podspec which has an optional subspec dependency. The intention is that a few clients which may need this SubsSpecDepenedency can include OptionalSubSpec as well and the rest of clients gets only the main spec and it's dependencies.
My Spec looks somethings like this :
Pod::Spec.new do |s|
s.name = 'main'
s.version = '123234'
s.author = { 'name' => 'email#' }
s.license = { "Confidential" }
s.homepage = 'https://....'
s.source = { :http => "URL-for-framework"}
s.summary = 'Dynamic framework'
s.source_files = 'dummy.m'
s.preserve_paths = '*'
s.ios.deployment_target = '9.0'
s.dependency 'dependency1', "123"
s.default_subspec = :none
s.subspec 'OptionalSubSpec' do |ss|
ss.dependency 'SubsSpecDepenedency', "456"
end
end
I do not want the OptionalSubSpec to be also installed along with pod main but even after specifying the s.default_subspec = :none as mentioned in the cocoa pod guide the SubsSpecDepenedency is being installed when i run pod install for pod main only.
How can I declare an optional dependency for my podsepc which is not always installed when the main/master spec is installed.
Divide the pod into two subspecs. Put everything you want to always install in the default_subspec. Put the optional bits in the other subspec.
Then the other subspec will only be installed if explicitly requested in the Podfile.
Related
Report
What did you do?
I have created podspec file for my custom Framework as:
Pod::Spec.new do |s|
s.platform = :ios
s.ios.deployment_target = '10.0'
s.name = "CustomFramework"
s.summary = "CustomFramework have all the wrapper API."
s.requires_arc = true
s.version = "1.0.0"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "My Name" => "my.name#xyz.com" }
s.homepage = "URL_LINK"
s.source = { :git => "github_url_link", :tag => "#{s.version}"}
s.dependency 'RealmSwift', '3.5.0'
s.dependency 'Firebase/Core', '5.1.0'
s.dependency 'Firebase/Firestore', '5.1.0'
s.dependency 'PubNub','4.7.5'
s.source_files = "CustomFramework/**/*.{swift}"
end
I am adding this Custom framework pod in the sample project as:
target 'customFrameworkSample' do
use_frameworks!
pod 'customFramework' , :path => 'Local_Path_for_customFramework.podspec'
target 'customFrameworkSampleTests' do
use_frameworks!
pod 'customFramework' , :path => 'Local_Path_for_customFramework.podspec'
end
end
What did you expect to happen?
Pod should install properly and When sample project is Build, it should Run and not throw any error.
What happened instead?
In the Sample project, error is thrown while importing firbase, RealmSwift files, etc.. in CustomFramework files.
CocoaPods Environment
cocoapod : 1.5.3
When you specify dependancies in your Podspec you are saying that YOUR CUSTOM FRAMEWORK is dependant on them. So the dependancies will only be available to reference within your framework. If you want the sample application to be able to reference Firebase then you will need to specify this within the sample application's podfile.
Documentation references:
Podspec 'dependancies'
Podfile 'dependancies'
make sure you have added firebase library in Linked framework and libraries
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 ?
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' => 'mail#example.com' }
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' => 'mail#example.com' }
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
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.
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.
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.
I'm trying to work out how to add a header file to a specific Podspec. I currently have to manually drag the file into the Pod's group in Xcode to get it to build. Otherwise it complains it cannot find the header file. I'd like to take this step out of the build process. I'm still learning the ins and outs of declaring dependencies in Cocoapods.
The Podspec is as follows:
Pod::Spec.new do |s|
s.name = 'ReactNativeCouchbaseLite'
s.version = '0.3.0'
s.summary = 'couchbase lite binding for react-native'
s.license = 'MIT'
s.platform = :ios, '7.0'
s.requires_arc = true
s.authors = 'Fraser Xu <xvfeng123#gmail.com>'
s.homepage = 'https://github.com/fraserxu/react-native-couchbase-lite.git'
s.source = { :git => 'https://github.com/fraserxu/react-native-couchbase-lite.git' }
s.source_files = 'ios/**/*.{h,m}'
s.dependency 'couchbase-lite-ios'
s.dependency 'couchbase-lite-ios/Listener'
# Current attempt to add the header file
s.subspec 'CBLRegisterJSViewCompiler' do |ss|
ss.source_files = 'Extras/CBLRegisterJSViewCompiler.h'
ss.preserve_paths = 'CouchbaseLite.framework'
ss.vendored_frameworks = 'CouchbaseLite.framework'
ss.dependency 'couchbase-lite-ios'
end
end
The header I need to add is CBLRegisterJSViewCompiler.h. In the release download of couchbase-lite-ios this header appears in the Extras folder.
Try this in your subspec.
ss.public_header_files = 'Extras/CBLRegisterJSViewCompiler.h'
Link back to CocoaPods reference.
I made a Swift framework I want to make a CocoaPods for it.
I've followed all the instructions:
created podspec file, added version tag, pushed it to github
When I run pod lib lint it passes but when I run pod spec lint it fails.
Here is my podspec file
Pod::Spec.new do |s|
s.name = "Seru"
s.version = "0.0.3"
s.summary = "Seru is Simple Core Data stack"
s.description = <<-DESC
Seru is Swift framework for working wit Core Data. It setup your core data stack and
gives you nica actions to work with it
DESC
s.homepage = "https://github.com/kostiakoval/Seru"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Kostiantyn Koval" => "konstantin.koval1#gmail.com" }
s.social_media_url = "http://twitter.com/kostiakoval"
s.platform = :ios, "8.0"
s.source = { :git => "https://github.com/kostiakoval/Seru.git", :tag => s.version }
s.source_files = "Seru/Source", "Seru/Source/**/*.{swift}"
s.requires_arc = true
s.ios.vendored_frameworks = 'Carthage/Build/iOS/Sweet.framework'
end
It has external framework dependency. I'm guessing this is a problem.
When I do pod speck lint, it says that I can't find that external framework
The problem was that CocoaPods don't include vendored_frameworks folder.
To fix it is to specify that this folder should be included to a CocoaPod by using preserve_paths.
s.preserve_paths = 'Carthage/Build/iOS/Sweet.framework'
So i figure this should be really easy but after a day of Googling and playing around i still can't seem to get this working. I have a private cocoapod which downloads code from a private git repository. This is all set-up and works fine.
What i'm struggling with is i need to include localized xibs in the cocoapod. I have a LoginView which is shared code across a number of our internal apps. However we have localised versions of the view. From what i can tell due to the way cocoapods flattens out the structure it's just copying the localized xib which is causing the *.lproj directories to be lost. When i then try and use the cocoapod it seems to pick up the first xib regardless of the language setting on the device.
I'm hoping someone might be able to guide me as to how i go about retaining the folder heirachy or if there's another way to include the localised xibs into the cocoapod.
#
# Be sure to run `pod lib lint NAME.podspec' to ensure this is a
# valid spec and remove all comments before submitting the spec.
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = "ios-XX-common"
s.version = "1.0"
s.summary = "XXXXXX"
s.description = "Pod containing common source code used across multiple apps"
s.homepage = "http://www.example.com"
s.license = 'Copyright'
s.author = { xxx }
s.source = { :git => "xxxx:/data/git/ios-xx-common.git", :tag => 'v1.0'}
s.platform = :ios, '7.0'
s.requires_arc = false
s.header_dir = 'ios-xx-common'
s.header_mappings_dir = 'CommonSourceCode'
s.source_files = "CommonSourceCode/**/*.{h,m}", "CommonSourceCode/CustomUIObjects/**/*.{h,m}",
"CommonSourceCode/Data Objects/**/*.{h,m}", "CommonSourceCode/Helpers/**/*.{h,m}",
"CommonSourceCode/UID/**/*.{h,m}", "CommonSourceCode/UIViews/**/*.{h,m}",
"CommonSourceCode/ViewControllers/**/*.{h,m}"
s.resource_bundles = { 'rr-common-xibs' => ['CommonResources/Xibs/*.lproj'],
'rr-common-other' => ['CommonResources/Icons/*.*', 'CommonResources/IPhone/*.*', 'CommonResources/IPhoneIPad/*.*', 'CommonResources/Sounds/*.*'] }
s.public_header_files = '**/*.h'
s.dependencies = { 'Parse-iOS-SDK' => '~> 1.2.19', 'CocoaLumberjack' => '~> 1.7.0',
'MBProgressHUD' => '~> 0.8', 'AFNetworking' => '~> 1.0' }
end
Thanks
I think you might be after "Development Pods".
So I have two projects, a library project and an app specific project.
In my library project I have a library.podspec file
Pod::Spec.new do |s|
s.name = "Library"
s.version = "0.0.1"
s.summary = "Shared library."
s.description = "This is an iOS library for shared common code across all apps"
s.homepage = "http://blah.com"
s.license = 'COMMERCIAL'
s.author = { "My name" => "my#email.com" }
s.social_media_url = "http://twitter.com/blah"
s.platform = :ios, '8.0'
s.source = { :git => "https://bitbucket.org/blah/library.git", :tag => '0.0.1' }
s.source_files = 'Library/Classes/**/*.{h,m}', 'Library/Models/**/*.{h,m}', 'Library/ViewModels/**/*.{h,m}', 'Library/Views/**/*.{h,m}'
s.resources = "Library/Images/**/*.png", "Library/Images/**/*.jpg", 'Library/Views/**/*.xib', "Library/Fonts/*.otf"
s.requires_arc = true
s.framework = 'MapKit', 'CoreLocation'
s.dependency 'AFNetworking'
s.dependency 'ReactiveCocoa'
s.dependency 'JLRoutes'
end
Then in my specific app project's Podfile...
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
link_with 'Myapp', 'Myapp-Tests'
pod 'Library', :path => '../library/'
Now when I run "pod update" for my specific app project I can see under the Pod project instead of under Pods, I have a new folder called Development Pods.
Just be aware that if you add new files in your Library project, be sure to pod update again.
Peace.