Remove dependency from pod - ios

How do I remove dependency from a pod?
I have a podfile with
pod 'GData'
which seems to be broken, because it generates 163 duplicate symbols errors. I think I know what it is. While installing this can be observed:
Installing GTMHTTPFetcher (1.141)
Installing gtm-http-fetcher (1.0.141)
[!] GTMHTTPFetcher has been deprecated in favor of gtm-http-fetcher
One of these is not needed. So to remove it I try to modify podfile to use custom, local podspec file:
podspec :path => '~/GData.podspec.json'
In which podspec file I copy all of original JSON podspec contents without GTMHTTPFetcher, GData DOES not install. It even happens if I just copy original contentes and don't change anything at all. All dependencies are installed, but GData itself is not. I think that I'm missing something here.

Here is proper podfile syntax for using custom podspec (in a JSON format):
pod 'pod_name_goes_here', :podspec => 'path/to/your/file.podspec.json'
And to delete dependency, simply remove an entry from 'dependencies', for example change
"dependencies": {
"GTMHTTPFetcher": [
],
"gtm-oauth2": [
]
}
to
"dependencies": {
"gtm-oauth2": [
]
}
And now pod will be installed without "GTMHTTPFetcher".

Related

Cocoapod subspec dependency not adding header/library search paths

I'm writing a Cocoapods podspec for a Swift library (https://github.com/promotedai/ios-metrics-sdk). One of our clients asked us to add Firebase Analytics tracking to the internals of this library. As a result, in the podspec, I broke the Firebase dependency into a subspec.
Pod::Spec.new do |s|
s.name = 'PromotedAIMetricsSDK'
...
s.subspec 'FirebaseAnalytics' do |a|
a.source_files = ['Sources/PromotedFirebaseAnalytics/**/*.{h,m,swift}']
a.dependency 'Firebase/Analytics', '~> 7.11.0'
a.dependency 'PromotedAIMetricsSDK/Core'
end
end
The problem I ran into was that the above subspec neither builds nor passes pod lib lint. The build complained about a missing Firebase framework, and the lint step complained about the same thing. I had to add the following xcconfig to the subspec to get things working.
analytics_xcconfig = {
'USER_HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/Firebase/CoreOnly/Sources"',
'FRAMEWORK_SEARCH_PATHS' => '"${PODS_XCFRAMEWORKS_BUILD_DIR}/FirebaseAnalytics" "${PODS_XCFRAMEWORKS_BUILD_DIR}/GoogleUtilities" "${PODS_XCFRAMEWORKS_BUILD_DIR}/nanopb"',
'OTHER_LDFLAGS' => '-framework "FirebaseAnalytics" -framework "GoogleUtilities" -framework "nanopb"'
}
s.subspec 'FirebaseAnalytics' do |a|
a.source_files = ['Sources/PromotedFirebaseAnalytics/**/*.{h,m,swift}']
a.dependency 'Firebase/Analytics', '~> 7.11.0'
a.dependency 'PromotedAIMetricsSDK/Core'
a.pod_target_xcconfig = analytics_xcconfig
end
While the above configuration allows the subspec to build and pass lint validation, it defeats the purpose of having a package manager take care of these dependencies. I have other subspecs that pull in dependencies that don't encounter the same problem. Also, pulling in Firebase/Analytics directly in the app's Podfile works fine.
Am I missing something? Is there a reason why Firebase/Analytics requires this xcconfig hack when building from a subspec of a podspec? Can I get rid of this hack somehow?
For a demonstration of this problem, pull the above repo and remove the a.pod_target_xcconfig = ... lines from the FirebaseAnalytics subspec, then run pod lib lint. Commit 67cb6173ee0f43b33cfb726b6337cc14463d220b in the repo demonstrates a similar problem where the linker can't find the FirebaseAnalytics framework (run pod lib lint on that commit).
I'm using Cocoapods 1.10.1, Xcode 12.5, and macOS 11.3.
Thanks,

How to use local-only project via CocoaPods

I am struggling to find a way to package an Xcode framework we created as a Pod that would only be used internally (not public, not on github).
How do I modify the .podspec to build the SDK from the local Xcode project on my development machine?
Local CocoaPods
[Dependency manager]
[Cocoapods with specyfic branch]
Example with Git:
Textual
Podfile
//Podfile pod supports:
//default(try to find .podcpec in centralised repo), path
//-remote
pod 'PodName'
//-local
//local_path can be absolute or relative
pod 'PodName', :path => '<local_path>.podspec'
Podspec
//Podspec source supports:
//git, svn, hg, http
//-remote
s.source = { :git => "https://url_to.git", :tag => "git_tag" }
//-local
s.source = { :git => 'file:///path_to_git_folder', :tag => "git_tag" }
//or, where path_to_git_folder can be relative
s.source = { :git => '/path_to_git_folder', :tag => "git_tag" }
Do not forget to commit your changes beforehand. git_tag can be the same as a branch name.
Several useful commands:
Update:
Podfile:
pod update
Check
.podspec:
pod spec lint "<some_path>.podspec" --quick
pod spec lint "<some_path>.podspec" --verbose --allow-warnings
Register session:
pod trunk register <email> '<name>' --description='<description>'
Release:
pod trunk push <file>.podspec --verbose --allow-warnings
Pod search[About]:
pod search <pod_name>
[Local Carthage]
[Local Swift Package Manager]
[Android Maven local]
Short answer: you don't use the .podspec for this. Longer: the .podfile is mainly for specifying:
external dependencies
what to snarf out of the project, relative to the project folder
IIRC, other than some informational metadata, the .podspec does not address how you get to that project folder, as this is handled separately.
As mentioned in the comments, you can use the Podfile to use a local project, with the :path => directive pointing to a local project folder. For example, you have the project in /Users/me/proj -- and the .podspec lives at the top-level -- your Podfile would have an entry like:
pod 'MyPodName', :path => '/Users/me/proj'
Warning: when you run pod {update, install}, this will pull whatever is checked out locally in that project at the time.
You just need a private Git repository, add as a source to Podfile
Then deciding if the framework is going to be closed source or open source, then podspec file will be different.
all the pod repo ... will help you Doc

Include static frameworks and libs on cocoapods

After spending hours, I definitely need your help.
I want to create a pod including Spotify SDK (here, it's a .framework) and Deezer SDK (here, it's a *.a lib) in order to do some work with.
Both SDK are written in Objective-C, and I want to write my pod in Swift 2 (iOS 8). Also, projects that will include this pod are in Swift 2 (iOS 8).
After the creation of the pod project with pod create lib I started by trying to add Spotify.framework directly in the pod project, but can't compile...
So, I tried to include the Spotify.framework like a pod by writing a podspec, here is spotify.podspec.json :
{
"name": "FakeSpotify",
"version": "1.1",
"summary": "Spotify iOS SDK",
"homepage": "https://developer.spotify.com/technologies/spotify-ios-sdk/",
"license": "MIT",
"authors": {
"jjt": "jeanjaques#thierry.com"
},
"source": {
"git": "https://github.com/spotify/ios-sdk.git",
"tag": "beta-13"
},
"platforms": {
"ios": "8.0"
},
"requires_arc": true,
"preserve_paths": "Spotify.framework",
"public_header_files": "Spotify.framework/Versions/A/Headers/*.h",
"vendored_frameworks": "Spotify.framework",
"xcconfig": {
"OTHER_LDFLAGS": "-ObjC"
}
}
And I Also added a line on the Podfile :
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target 'SpoTest_Example', :exclusive => true do
pod 'SpoTest', :path => '../'
pod 'FakeSpotify', :podspec => './spotify.podspec.json'
end
target 'SpoTest_Tests', :exclusive => true do
pod 'SpoTest', :path => '../'
end
Now, after a pod install, a folder "FakeSpotify" is created with the the Spotify.framework in it. This part is ok, but it's not enough : I can't use it...
I can't import Spotify neither in the example project, nor in the development pods files (both in Swift).
I tried to add #import <Spotify/Spotify.framework in the umbrella file (SpoTest-umbrella.h), but there were an error : Include of non-modular header inside framework module 'SpoTest'.
After hitting myself and some search, I tried to edit my podfile by adding this post script :
post_install do |installer|
installer.pods_project.build_configuration_list.build_configurations.each do |configuration|
configuration.build_settings['CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES'] = 'YES'
end
end
Nothing better, same error. Ok ok, what can I do ? Hmmm, I tried to remove the previously added import in umbrella file and I edited my pod podspec (SpoTest.podspec). I cried "ohhh I'm really bad, we need to also tell that we have a dependency in this podspec, even for development test...".
So I added this beautiful line : s.dependency 'FakeSpotify'
I was so happy, ... and so sad : new error from pod install command now :
[!] The 'Pods-SpoTest_Example' target has transitive dependencies that include static binaries: (/Users/jjt/Documents/dev/ios/LIBS/SpoTest/Example/Pods/FakeSpotify/Spotify.framework)
Ouch, so close ! Ok, let's try something to deal with it. I edited my Podfile by adding a pre install script :
pre_install do |installer|
# workaround for https://github.com/CocoaPods/CocoaPods/issues/3289
def installer.verify_no_static_framework_transitive_dependencies; end
end
With this, the command line is ok, and the installation is done. But I still can't use it. And there is still an error if I import the framework in umbrella.
Do you have any more ideas ? I currently don't have more :)
Or maybe there is a better way without cocoapods ? My goal is to create a something with these two SDK, and to include it easily on others reals projects.
Thanks.

How to import Alamofire/AFNetworking in my custom cocoapod

How do I include Alamofire (a web request pod like AFNetworking) in my cocoapod source files? I have a service in my cocoapod that needs to make web requests using Alamofire, my cocoapod doesn't seem to have a podfile that I can see, so I don't know how to add the dependency to my cocoapod.
I am creating a cocoapod using pod lib create The build fails whenever I go to import Alamofire in any of my files. In a normal project, I'd just add Alamofire to my podfile, but this is a cocoapod, so I can't figure out where to add the dependency, or how to get it to build successfully.
I followed the guide here but it doesn't say anything about importing another pod into my cocoapod's files.
My directory structure looks like this:
MyLib.podspec
Example/
MyLib example project
Pod/
Source files for my cocoapod
If your pod depends on other pods you can define that in your pod's .podspec file. You can add dependencies there.
Have a look at RealmSwift's podspec file as an example. The RealmSwift pod has a dependency to the Realm pod. This is defined in RealmSwift.podspec:
Pod::Spec.new do |s|
s.name = 'RealmSwift'
s.version = `sh build.sh get-version`
s.summary = 'Realm is a modern data framework & database for iOS & OS X.'
s.description = <<-DESC
The Realm database, for Swift. (If you want to use Realm from Objective-C, see the “Realm” pod.)
Realm is a mobile database: a replacement for Core Data & SQLite. You can use it on iOS & OS X. Realm is not an ORM on top SQLite: instead it uses its own persistence engine, built for simplicity (& speed). Learn more and get help at https://realm.io
DESC
s.homepage = "https://realm.io"
s.source = { :git => 'https://github.com/realm/realm-cocoa.git', :tag => "v#{s.version}" }
s.author = { 'Realm' => 'help#realm.io' }
s.requires_arc = true
s.social_media_url = 'https://twitter.com/realm'
s.documentation_url = "https://realm.io/docs/swift/#{s.version}"
s.license = { :type => 'Apache 2.0', :file => 'LICENSE' }
# ↓↓↓ THIS IS WHERE YOU DEFINE THE DEPENDENCY TO ANOTHER POD ↓↓↓
s.dependency 'Realm', "= #{s.version}"
# ↑↑↑ THIS IS WHERE YOU DEFINE THE DEPENDENCY TO ANOTHER POD ↑↑↑
s.source_files = 'RealmSwift/*.swift'
s.prepare_command = 'sh build.sh cocoapods-setup without-core'
s.preserve_paths = %w(build.sh)
s.pod_target_xcconfig = { 'SWIFT_WHOLE_MODULE_OPTIMIZATION' => 'YES',
'APPLICATION_EXTENSION_API_ONLY' => 'YES' }
s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.9'
s.watchos.deployment_target = '2.0' if s.respond_to?(:watchos)
end
You should check out the AlamofireImage project. It uses Carthage to add the Alamofire submodule to the project. The Alamofire project is then added as a dependency to the AlamofireImage project.
The AlamofireImage.podspec also demonstrates how to add Alamofire as a dependency for CocoaPods. If you follow the AlamofireImage project structure exactly, you'll be up and running in no time. Here are some useful commands to get you going:
Cartfile
github "Alamofire/Alamofire" ~> 3.0
Checkout through Carthage
brew update
brew doctor
brew install carthage
// or
brew upgrade carthage
carthage update --no-build --use-submodules
Hopefully that helps!
If you have created a pod and in your .podspec file you are trying to add a dependency (like Alamofire, RealmSwift..) after that you should go to the Example/.. folder and do a pod install to make the dependencies required from the .podspec of your custom pod visible to the .swift files in your custom pod/framework.
A typical example of a pod project folder hierarchy would be:
- MyLib/
- _Pods.xcodeproj
- Example/ // <-- do a pod install under this folder in order to get the dependencies declared in your .podspec
- Podfile
- MyLib.xcodeproj
- MyLib.xcworkspace
- MyLib/
- Classes/ // <-- folder with pod specific logic that also uses Alamofire
- Assets/
- MyLib.podspec // <-- your podspec with dependencies (Alamofire..)

How to add dependency to Cocoapods

I am trying to create a Cocoapods library. My library will include Google-Mobile-Ads-SDK as dependency. I used following commands
pod lib create BannerViewController
> my email address
What language do you want to use?? [ ObjC / Swift ]
> Swift
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
Which testing frameworks will you use? [ Quick / None ]
> None
Would you like to do view based testing? [ Yes / No ]
> No
I then edited BannerViewController.podspec added following line
s.dependency 'Google-Mobile-Ads-SDK', '~> 7.0'
I tried to use pod lib lint BannerViewController.podspec
[!] BannerViewController did not pass validation, due to 1 error and 3 warnings.
You can use the `--no-clean` option to inspect any issue.
I tried to pod update in Example directory and got following error
[!] The 'Pods-BannerViewController_Example' target has transitive dependencies that include static binaries: (/Developer/BannerViewController/Example/Pods/Google-Mobile-Ads-SDK/GoogleMobileAdsSdkiOS-7.4.0/GoogleMobileAds.framework)
I don't know how can I add Google-Mobile-Ads-SDK to my development pod so that I can test my code locally. Cocoapods documentation is not clear. I am using Cocoapods 0.38.2
Use pod lib lint BannerViewController.podspec --use-libraries

Resources