I am setting up a Swift framework through CocoaPods.
Goals are:
Use a private repo for the Podspecs
Have the framework to be distributed as binary (as opposed to source code)
I've read already the CocoaPods frameworks, Making a CocoaPod plus other references (can't seem to be able to include more than 2 links with current SO reputation but I can point sources in comments).
The Podspec I am using is:
Pod::Spec.new do |s|
s.name = 'SDK'
s.version = '0.0.1'
s.summary = 'My SDK'
s.description = 'SDKs description'
s.homepage = 'https://github.com/XXX/sdk'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'XXX' => 'xxx#xxx.com' }
s.source = { :git => 'https://github.com/XXX/sdk.git', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'
s.platform = :ios, '9.0'
s.source_files = 'SDK/Classes/**/*'
s.preserve_paths = 'Frameworks/SDK.framework'
s.ios.vendored_frameworks = 'Frameworks/SDK.framework'
end
The Pods xcode project was changed to build also i386 arch besides the standard (arm64, armv7).
This spec successfully validates locally with, provided that I copy the SDK.framework file to the /Frameworks folder in the .podspec folder:
pod lib lint
Issue: when I try to push the spec to the repo, the validation fails as the output below show:
pod repo push mySDKPrivateRepo SDK.podspec
Validating spec
-> SDK (0.0.1)
- ERROR | [iOS] file patterns: The `source_files` pattern did not match any file.
- ERROR | file patterns: The `preserve_paths` pattern did not match any file.
- ERROR | [iOS] file patterns: The `vendored_frameworks` pattern did not match any file.
[!] The `SDK.podspec` specification does not validate.
Questions:
How can I make the podspec validation successful when pushing it to repo?
Other notes:
Copying the SDK.framework to /Frameworks works manually.
If I include a Copy Files build step in the Pods Xcode project the file is not copied.
Using CocoaPods 1.1.0.
I was having a similar problem, the culprit was the project structure itself.
Be sure to check your at which directory you're pointing your source_files to. I've found that maintaining any kind of structure in this way is very difficult and it's easier to include all of your files in a single folder.
s.source_files = '<InsertName>/**/Classes/*'
Take a look at cocoapods advice on File Patters for some help on this.
By a process of elimination, I would suggest trying to push to the repo commenting out source_files in the podspec first, and work your way forward from there.
Related
I created my first cocoapod from a personal repo, and deployed it to cocoapods via the pod trunk push command. Since it is my first framework, I wanted to develop it on a personal repo to keep my messy commits private. Now that the product is ready, I need to migrate the work over to an open source repo, and update the cocoapod's source.
I tried changing the s.homepage and s.source lines of the podspec, but I get this fatal: Remote branch 1.0.0 not found in upstream origin error.
Updating spec repo `master`
Validating podspec
-> EvolvKit (1.0.0)
- ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/evolv-ai/EvolvKit.git /var/folders/jb/xlkpf4sn6fl9wtsh3g7pkqrh0000gp/T/d20190729-87754-7w53ir --template= --single-branch --depth 1 --branch 1.0.0
Cloning into '/var/folders/jb/xlkpf4sn6fl9wtsh3g7pkqrh0000gp/T/d20190729-87754-7w53ir'...
warning: Could not find remote branch 1.0.0 to clone.
fatal: Remote branch 1.0.0 not found in upstream origin
) during validation.
[!] The spec did not pass validation, due to 1 error and 1 warning.
➜ EvolvKit git:(master)
old pod spec:
Pod::Spec.new do |s|
# more configs
s.homepage = 'https://github.com/<personal_repo>/EvolvKit'
s.license = { :type => 'APACHE', :file => 'LICENSE' }
s.author = { 'PhyllisWong' => 'phyllis.wong#evolv.ai' }
s.source = { :git => 'https://github.com/<personal_repo>/EvolvKit.git', :tag => s.version.to_s }
# more configs
end
The new podspec lines changed:
s.homepage = 'https://github.com/<opensource_repo>/EvolvKit'
s.source = { :git => 'https://github.com/<opensource_repo>/EvolvKit.git', :tag => s.version.to_s }
Some things I tried are:
0. update git tag with version 1.0.0
1. updating the urls in the pod spec
2. clone the repo into a new directory, create a new git repo, and follow steps to trunk push
3. deleting the pod (was only able to delete versions) ...no one is using this pod btw.
4. considered changing the pod name, but that is less than ideal
Any ideas about a good way to go forward is greatly appreciated.
edit
Turns out I was missing a step in updating my repo with the git tag. Needed to push the tags.
Building off of my above comment about tagging the branch, did you git push --tags as well? Applying tags is a two step process, and without both, you can get the above error.
Since Xcode 9 it is possible to use static libraries by omitting the use_frameworks! flag in the Podfile. However, when used with the Pod RealmSwift this results in the following error:
[!] The following Swift pods cannot yet be integrated as static libraries:
The Swift pod `RealmSwift` depends upon `Realm`, which do not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.
Sadly, the proposed solution with use_modular_headers! does not work.
Other things I have tried include:
Using the latest Realm version (3.15.0)
Use the Objective C version and add Swift support, this won't build and give a module not found error in the RLMSupport.swift file .
Adding a bridging header for the Objective C version.
Endless clean, rebuild, Xcode relaunches and Derived Data folder cleaning.
It would not be preferable to circumvent CocoaPods and have this dependency be installed in a separate way, since that would make updating a more complex process. I hope there is a solution that works with CocoaPods, Realm and Swift.
I did the job doing following:
pod 'RealmSwift', '~> 3.17', :modular_headers => true
pod 'Realm', '~> 3.17', :modular_headers => true
As far as I can tell adding use_modular_headers! to top of Podfile works.
Adding s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } to .podspec doesn't work as far as I can tell. (Cocoapods 1.6.0-beta.2)
example:
target 'Opportunity' do
use_modular_headers!
end
I don't see why it wouldn't work. I got the same issue, and I added use_modular_headers! following way in the podfile and it worked.
target 'Pick Up Lines' do
use_modular_headers!
pod 'RealmSwift'
end
By the way, before doing any of it, make sure, you set the deployment target of the project as 11.0.
I can’t push a new version of my pod to the CocoaPods specs repository.
Running pod trunk push MyPod.podspec results in the following error:
[!] The Pod Specification did not pass validation.
The following validation failed:
- Warnings: Unrecognized `swift_version` key.
Here’s my podspec:
Pod::Spec.new do |spec|
spec.name = "MyPod"
spec.version = "0.1.1"
spec.summary = "[REDACTED]"
spec.homepage = "[REDACTED]"
spec.license = "Apache License, version 2"
spec.author = "[REDACTED]"
spec.social_media_url = "[REDACTED]"
spec.module_name = "MyPod"
spec.swift_version = "5.0"
spec.platform = :ios, "8.0"
spec.source = { :git => "https://github.com/[REDACTED].git", :tag => "v#{spec.version}" }
spec.source_files = "MyPod/**/*.{h,m,swift}"
end
What am I doing wrong?
I first noticed these errors before updating to Swift 5 and Xcode 10.2.
It seems to be a server-side bug. It’s been reported on GitHub.
However, since it’s a warning, not an error (despite it’s in red font color, which is confusing), it can be ignored with the --allow-warnings argument.
Summary, to update a pod:
Update the version and the tag in podspec beforehand
Commit, push code to git
Create new tag with the current code, make sure it's the same tag as the one in podspec
git tag 0.1.1
git push origin 0.1.1
Call pod spec lint to check and pod trunk push to update it on repo master list
pod lib lint YourSDK.podspec
pod trunk push YourSDK.podspec
It appears that your podfile is using the tag v0.1.1, however the tag in your repository is 0.1.1 without the v. This would also cause linting to fail.
I am referencing the pod 'MatomoTracker' in my own pod
I get this error while linting : with pod lint spec
-> TrackerPod.v3 (0.0.1)
- ERROR | [iOS] unknown: Encountered an unknown error (CocoaPods could not find compatible versions for pod "Pods/MatomoTracker/MatomoTracker":
In Podfile:
TrackerPod.v3 (from `/Users/****/Documents/projects/ios/libs/TrackerPod.v3/TrackerPod.v3.podspec`) was resolved to 0.0.1, which depends on
TrackerPod.v3/Matomo (= 0.0.1) was resolved to 0.0.1, which depends on
Pods/MatomoTracker/MatomoTracker (= 5.2.0)
None of your spec sources contain a spec satisfying the dependency: `Pods/MatomoTracker/MatomoTracker (= 5.2.0)`.
You have either:
* out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
* mistyped the name or version.
* not added the source repo that hosts the Podspec to your Podfile.
Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default.) during validation.
Analyzed 1 podspec.
[!] The spec did not pass validation, due to 1 error.
this is my podspec:
Pod::Spec.new do |spec|
spec.name = 'TrackerPod.v3'
spec.version = '0.0.1'
spec.license = 'Copyright ****'
spec.homepage = 'https://*******8/TrackerPod/blob/master/README.md'
spec.author = { '****' => '****#****.com' }
spec.summary = 'Some description'
spec.source = { :git => '****', :tag => spec.version.to_s }
spec.source_files = 'TrackerPod.v3/*.{h,m, swift}'
spec.ios.deployment_target = '8.0'
spec.osx.deployment_target = '10.10'
spec.requires_arc = true
spec.swift_version = '4.0'
spec.xcconfig = { 'SWIFT_VERSION' => '4.1' }
spec.dependency 'MatomoTracker', '5.2.0'
spec.subspec 'Matomo' do |lib|
lib.dependency 'Pods/MatomoTracker/MatomoTracker', '5.2.0'
lib.source_files = 'Pods/MatomoTracker/MatomoTracker/**/*.{h,m,swift}'
end
end
and, this is a screenshot to show my project navigator.
You can see that MatomoTracker is nested 2 levels downs inside 'Pods'
the project navigator
Am using the right path to reference MatomoTracker Pods/MatomoTracker/MatomoTracker, it does not seem to find the pod Matomoto ?
Am I correct ?
to answer the question. I kind of know where the error stands.
In my podspec, I am using spec.dependency 'MatomoTracker', '~> 5.2'
without the above the line, the validation passes
it seems that a higher minimum deployment target is required. I have update to deployment target as 11.0 everywhere.
- Podfile
- build settings (pod target) in Xcode
- spec ios target as well in the pod spec
and, this is the error I get
ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
ERROR | [OSX] unknown: Encountered an unknown error (CocoaPods could not find compatible versions for pod "MatomoTracker":
In Podfile:
TrackerPod.v3 (from `/Users/*****/Documents/projects/ios/libs/TrackerPod.v3`) was resolved to 0.0.1, which depends on
MatomoTracker (~> 5.2)
Specs satisfying the `MatomoTracker (~> 5.2)` dependency were found, but they required a higher minimum deployment target.) during validation.
Although I feel like I did by the book and as per the cocoapods guide, I am still missing sthg.
The MatomoTracker does not pass the validation
I'm trying to create a pod APod which has a 'AAnalytics' as a subspace. ''AAnalytics' has multiple dependencies such as Firebase and NewRelic. Here's how the podspec looks like:
Pod::Spec.new do |s|
s.name = 'APod'
s.version = '0.3.5'
s.summary = 'summary'
s.ios.deployment_target = '9.0'
s.tvos.deployment_target = '9.0'
s.watchos.deployment_target = '2.0'
s.static_framework = true
s.source_files = 'APod/Classes/*'
#### Subspec ####
s.subspec 'AAnalytics' do |ss|
ss.pod_target_xcconfig = { 'DEFINES_MODULE' => 'Yes' }
ss.source_files = 'Classes/AAnalytics/*'
ss.dependency 'NewRelicAgent', '~> 5.15.0'
ss.dependency 'Analytics', '~> 3.6.0'
ss.dependency 'Segment-Adjust', '~> 1.1.3'
ss.dependency 'FBSDKCoreKit', '~> 4.27.1'
ss.dependency 'Firebase/Core', '~> 4.4.0'
end
end
In AAnalytics, it has only one class AAnalytics.swift which has a wrapper methods of dependency pods. Everything works fine except NewRelicAgent. I can't import and use NewRelicAgent in Analytics.swift. However I could use NewRelicAgent in main project with bridging header.
After I searched for a while, I found that Xcode doesn't create module.modulemap file for NewRelicAgent (or it should be included in NewRelicAgent pod).
As you see above, FirebaseAnalytics has `Modules/module.modulemap'.
However NewRelicAgent doesn't have the path and file.
I have read this article and it seems Xcode create module.modulemap file if DEFINES_MODULE = Yes and there is a umbrella header which has same name with framework.
What am I missing and What should I do to use NewRelicAgent from AAnalytics.swift? I'm using cocoapods 1.4.1 beta 2.
Xcode doesn't generates module.modulemap files for binary frameworks. NewRelicAgent is a vendored_framework binary CocoaPod that doesn't include a module map. Other CocoaPod's include a module.modulemap within their framework.
If you do find . | grep module.modulemap, you'll see that the other binary CocoaPods with public APIs in your project include a Modules/module.modulemap file.