Cocoapod podspec validation - Unknown DSL error occured - ios

Im trying to upload the new version of my pod to cocoapods spec repo. The current live version is 0.3.1 and it is a framework build with swift 4.2. Now i updated the library and build with Xcode 11.1 (swift 5). But while linting the podspec file, im getting an unknown DSL error in the terminal.
I have tried with changing the name of podspec and with same framework. but no use. anyone please help
pod spec lint AsistaCore.podspec --verbose
Podspec file
Pod::Spec.new do |spec|
spec.name = 'AsistaCore'
spec.version = '1.0.0'
spec.summary = 'Official Asista SDK in Swift to access Asista Platform core feature'
spec.description = <<-DESC
The Asista SDK in Swift Core framework provides:
* Create new tickets
* Update Ticket State
* Add comments to ticket
* Asset list
* Update profile
* Knowledge Base Articles
DESC
spec.homepage = 'https://asista.com/developer'
spec.license = { :type => 'MIT', :file => 'LICENSE' }
spec.authors = { 'Cherrylabs' => 'vaisakh.kp#cherrylabs.com' }
spec.documentation_url = 'https://asista.com/developer/docs/asista-sdk-for-ios'
spec.platform = :ios
spec.source = { :git => 'https://github.com/cherrylabstech/asista-sdk-ios.git', :tag => spec.version }
spec.swift_version = '5.0'
spec.ios.deployment_target = '8.0'
spec.static_framework = true
spec.ios.vendored_frameworks = 'AsistaSupport/AsistaCore.framework'
end
-> AsistaCore (1.0.0)
- ERROR | [iOS] unknown: Encountered an unknown error (Pod::DSLError
/Library/Ruby/Gems/2.6.0/gems/cocoapods-core-1.8.4/lib/cocoapods-core/specification.rb:808:in `rescue in _eval_podspec'
....
...

We ran into this issue when we try creating a release and publishing a library. This error occurs when you are trying to run pod spec lint or pod repo push. The error says "DSLError" and doesn't give much information on what is causing it. I found little help online and some places they say, there could be a syntax error in the podspec file. We didn't have any in our podspec. However, this answer from stackoverflow gave me some direction https://stackoverflow.com/a/64779582
It looks like while making a release for one SDK/library, the pod spec lint and pod repo push validates all the podspecs in the folder besides the ones you ran. I don't know how that works internally. You should look for the following scenarios to identify the issue:
If there are other podspecs for capabilities that have different tags(Example: ABC.podspec pointed to source tag 1.0.0-ABC and XYZ.podspec pointed to source tag 2.0.0-XYZ)
Multiple podspecs have dependencies on different versions of the same module(Example: Module1.podspec depends on Module 5 version 10.0.0 and Module2.podspec also depends on Module 5 but on the version 11.0.0).
Syntax errors in any of the podspecs
If you come across either or both 1 & 2, it could be a potential cause for the DSLError.
When you run into this issue, make sure you look for and update the following:
All podspecs to have pointed to one source tag
All dependencies on a module pointed to one version of it in each capability.
Fix the sytanx errors.
This issue will go away or reduce significantly when the SDK libraries can be separated into their repositories instead of all in one repository, or perhaps even by keeping each podspec in their own individual folder.

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,

Unable to add iOS dependency to Flutter plugin

I am creating a Flutter plugin. But when I am trying to add a dependency to iOS part of the plugin I am not finding any proper guideline for this. I declared the dependency in the podspec file of my plugin. But the dependency is only available in the example/ios through Pod but I want access that dependency in my ios folder of my plugin. This is my podspec:
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'comet_chat'
s.version = '0.0.1'
s.summary = 'A new Flutter plugin.'
s.description = <<-DESC
A new Flutter plugin.
DESC
s.homepage = 'http://example.com'
s.license = { :file => '../LICENSE' }
s.author = { 'Your Company' => 'email#example.com' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'CometChatPro', '1.4.0'
s.ios.deployment_target = '10.0'
s.preserve_paths = 'CometChatPro.framework'
s.xcconfig = { 'OTHER_LDFLAGS' => '-framework CometChatPro' }
s.vendored_frameworks = 'CometChatPro.framework'
end
I followed this issue but it was of no help. How to solve this issue? How can I get my dependency only for the plugin?
There is no way to "only open the plugin's classes", and the dependencies you add in your podspec are only available to your plugin, unless explicitly made it public.
TL;DR
By design, your iOS Flutter plugin will always run when embedded in a Flutter application project. Also, there is a conflict in your podspec; it should never specify the same framework in both dependency and vendored_frameworks.
If you have a CometChatPro.framework folder, copy it in your plugin's ios/Libraries folder and declare its path in your podspec in vendored_frameworks. Personally, I've never used the dependency specifier but there is an example in the flutter-webrtc plugin's implementation.
Either way, the ios/Classes folder of your plugin does have access to the dependencies that you specify in your ios/plugin_name.podpsec file. It just doesn't "know it" when you edit your plugin in any editor other than Xcode (Visual Studio Code, Android Studio, etc).
To develop the Swift or Objective-C classes for your plugin's iOS implementation, you should :
Open the example's Xcode workspace located at example/ios/Runner.xcworkspace.
Edit your plugin's iOS classes by navigating in Xcode to Pods/Development Pods/plugin_name/../../ios/.symlinks/plugins/plugin_name/ios/Classes
Build your project to fix any compiling errors.
If at this point you still don't have access to the framework in your plugin's iOS classes, it means that it wasn't properly setup by Cocoapods. In that case, you'll need to find which Xcode Build Setting is not properly set and then specify these Build Settings in your plugin's podspec, like so:
s.xcconfig = {
'FRAMEWORK_SEARCH_PATHS' => ['${PODS_TARGET_SRCROOT}/Libraries'],
'HEADER_SEARCH_PATHS' => ["${PODS_ROOT}/../.symlinks/plugins/plugin_name/ios/Libraries/CometChatPro.framework/Headers"
}
This explicitly adds the framework to your plugin target's FRAMEWORK_SEARCH_PATHS, and the framework's Headers path to the HEADER_SEARCH_PATH.
When linking vendored_frameworks, you want to make sure that Cocoapods did successfully embed the framework, and that you are building for the right architectures.

Conflicts with FlutterFire and native GeoFire plugin on iOS

I'm getting an error when I'm trying to add GeoFire to my iOS Flutter project which has the FlutterFire Database plugin included. This is what the error looks like:
Resolving dependencies of `Podfile`
[!] Unable to satisfy the following requirements:
- `Firebase (~> 2.1)` required by `GeoFire (1.1.0)`
Specs satisfying the `Firebase (~> 2.1)` dependency were found, but they required a higher minimum deployment target.
My podspec file looks like this atm:
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'geofire'
s.version = '0.0.1'
s.summary = 'A new flutter plugin project.'
s.description = <<-DESC
A new flutter plugin project.
DESC
s.homepage = 'http://example.com'
s.license = { :file => '../LICENSE' }
s.author = { 'Your Company' => 'email#example.com' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'GeoFire', '>= 1.1' # Adding GeoFire
s.ios.deployment_target = '8.0'
end
I also tried using the git page in to add Geofire in my podspec file as suggested here: GeoFire giving problems with CocoaPods
s.dependency 'GeoFire', :git => 'https://github.com/firebase/geofire-objc.git'
Is there a (simple) solution for this?
I faced the same kind of issue few days ago.
I think I fixed it by doing the following steps:
Run the command 'pod repo update' (it will update your repo information)
Then run the command 'pod update' (it will update your pods using the latest repo information)
Let me know if this is solving your issue :)
Please try the approach suggested by Bjørn Børresen here:
Since Flutter kind of abstracts away this Cocoapods process. Here's what I did to be able to run "pod repo / update":
Run pod repo update
Set the environment variable FLUTTER_FRAMEWORK_DIR to something that looks like /Users/youruser/bin/flutter/bin/cache/artifacts/engine/ios/. You can do a locate Flutter.podspec to find this directory
From YourFlutterProject/ios run pod update
After this you should be able to run your app again

Cannot Lint/Push a Swift Cocoapods podspec

I tried to create my first podspec combining ObjC and Swift code, but I soon stumbled uppon a stubborn error that I cannot solve while uploading
Copying MyLibrary from /Users/lukasschwoebel/Library/Caches/CocoaPods/Pods/External/MyLibrary/540307feb534d63ad9015f3f6452b3ad-be661 to
../../../../../../private/var/folders/2p/_pc_vts51b3_pfydgm7_2n200000gn/T/CocoaPods/Lint/Pods/MyLibrary
- Running pre install hooks
-> MyLibrary (0.1.0)
- ERROR | [iOS] Encountered an unknown error (Pods written in Swift can only be integrated as frameworks; this feature is still in beta. Add use_frameworks! to your Podfile or target to opt into using it. The Swift Pod being used is: MyLibrary) during validation.
Here is the command I use:
pod repo push test-podspecs MyLibrary/MyLibrary.podspec --use-libraries --allow-warnings --verbose
As you might see, this is the minimum untouched sample project from CocoaPods as described here: https://guides.cocoapods.org/making/using-pod-lib-create.html
As I can not even make this sample running, I suspect something wrong with my cocoapods configuration.
I made sure there is no single Objective C line in the pod that is to be uploaded (though in the end, I would like to have a podspec with ObjC and Swift code mixed, but at this time I just want to have a working podspec with Swift).
I cannot even upload this simple pod with pure Swift. I first tried with CocoaPods v0.39.0, then downgraded to 0.38.2 and after that 0.38.0, even 0.36.0. Even with a complete un-install of CocoaPods.
It seems I need to configure something in CocoaPods to be able to upload a Swift podspec? The error I get obviously is during the building-phase of the pod where the Podfile needs use_frameworks! to be included. So how can I make CocoaPods use it while compiling the pod during the podspec verification?
Also, I have Xcode 7.0.1 and OSX 10.10.5 installed and it is Swift 2.0 code.
Thank you in advance!
Here is the complete podspec, adapted from the original created MyLibrary.podspec (and yes, that is a local Podspec-Repo, but that does not cause/change the error)
Pod::Spec.new do |s|
s.name = "MyLibrary"
s.version = "0.1.0"
s.summary = "A short description of MyLibrary."
s.description = 'Sample Description'
s.license = 'MIT'
s.author = { "Luke A." => "ls#mymail.to" }
s.source = { :git => "file:///Users/.../test/MyLibrary/", :tag => s.version.to_s }
s.platform = :ios, '8.0'
s.requires_arc = true
s.source_files = 'Pod/Classes/**/*'
s.resource_bundles = {
'MyLibrary' => ['Pod/Assets/*.png']
}
s.frameworks = 'UIKit'
end
I just found the answer, which seems a little obvious.
The command to upload/push the pod was in a bash-script so I did not always have to type all the flags but just and over the filename/path to the podspec. So in the default bash-script I had the flag --use-libraries which is required for one of my pods.
As I was trying something out and had a typo in the pod repo push .. command I stumbled across the man-page:
--use-libraries
Linter uses static libraries to install the spec
With static libraries, this flag seems to be incompatible with Swift podspecs. Removing that flag lints and pushes my podspec successfully.

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..)

Resources