create Pod with bridging header - swift

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.

Related

Migrate my pod to Swift 4

I created my pod in Swift 3 and now I wanna migrate it to Swift 4.
I've already done the code migration in the Example project (I chose to create an example when running pod lib create), but my podspec is still not passing validation.
One of the reasons is that the default cocoapods configuration is compiling it as Swift 3.
The other is that in order to update the dependencies to compile with Swift 4, I need to reference a specific branch, like RxSwift, but I couldn't find a way to do that in the podspec.
How can I fix those problems?
As per the CocoaPods: point to a branch in pod spec
You can't use :git and :branch metadata in podspec. It is expected that the :git and :branch metadata will come from the podfile.
If you want to use tags then use like below : RxCocoa/RxSwift for swift 4 tag(4.0.0-beta.0)
Pod::Spec.new do |s|
###Your code here
s.dependency 'RxCocoa', '~> 4.0.0-beta.0'
s.dependency 'RxSwift', '~> 4.0.0-beta.0'
end
If you want to use branch, then
Your podspecis like below :
Pod::Spec.new do |s|
###Your code here
s.dependency 'RxSwift'
end
Your Podfile will be :
use_frameworks!
target 'YOUR_TARGET' do
pod 'RxSwift', :git => 'https://github.com/ReactiveX/RxSwift.git', :branch => 'rxswift4.0-swift4.0'
end

Adding static libraries to pod spec file

I am trying to create a framework out of the app that is using Google maps now.
This is my FuelMap framework podspec
target 'FuelMap' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'GoogleMaps'
end
podspec:
Pod::Spec.new do |s|
...
s.dependency 'GoogleMaps'
s.dependency 'Google-Maps-iOS-Utils'
end
Then, I have a regular project which has this pod file
target 'Mock' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'FuelMap', :path => './FuelMap'
end
Since the regular project is using use_frameworks
I keep running into this error whenever I do pod install
The 'Pods-Mock' target has transitive dependencies that include static binaries:
Is there a work around, so that I can have the library file from GoogleMap Ios statically in the touch framework and then add them as a reference in the pod spec file. So the error would be avoid?

Cocoapods - podspec validates but can't be pushed to repo

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.

Overlapping pod dependencies

I am using cocoapods 0.39. I added Cocoa Touch Framework "MyFramework" as a separate target to my Swift project. The framework is using Firebase as a Cocoapod dependency. I am using MyFramework inside the the app. When I try to build the app I get multiple errors:
class … is implemented in both …/MyFramework.framework/MyFramework and …/MyApp.app/MyApp. One of the two will be used. Which one is undefined.
I understand what this error is about, but I am not able to fix it. If I remove Firebase from MyApp target then I can't use MyFramework inside the app as it depends on it. It looks like a common problem, but unfortunately I can't make it work.
My Podfile looks like this:
use_frameworks!
target 'MyApp' do
pod 'Firebase'
end
target 'MyAppTests' do
end
target 'MyFramework' do
pod 'Firebase'
end
target 'MyFrameworkTests' do
pod 'Firebase'
end
You are linking Firebase twice.
You can use inherit! :search_patchs directive in Podfile (requires Cocoapods 1.0 or higher) to let MyApp know about the dependencies without actually linking them:
use_frameworks!
target 'MyFramework' do
pod 'Firebase'
pod 'FirebaseAnalytics'
target 'MyApp' do
inherit! :search_paths
end
end
This requires that you explicitly declare dependencies in your Podfile to make them available in MyApp target. For example, adding pod 'Firebase' won't make using FirebaseAnalytics available in your application.
You can also convert MyFramework to a CocoaPod dependency and let CocoaPods handle the dependencies for you. To do this, create a Podspec file for your framework, like this:
Pod::Spec.new do |s|
# Meta data
s.name = "MyFramework"
s.version = "1.0.0"
s.platform = :ios
s.ios.deployment_target = '8.0'
s.summary = "-"
s.homepage = "-"
s.license = { :type => "MIT" }
s.author = { "Me" => "-" }
s.platform = :ios
s.ios.deployment_target = '8.0'
s.source = { :path => "MyFramework" }
# Source configuration
s.source_files = "MyFramework/**/*.swift"
s.resources = "MyFramework/**/*.{png,jpeg,jpg,storyboard,xib,strings}"
s.requires_arc = true
# Dependencies
# Firebase for iOS
s.dependency 'Firebase', '~> 3.0'
end
Then, you can add a development dependency to MyFramework in your application Podfile and remove Firebase dependency:
target 'MyApp' do
pod 'MyFramework', :path => '.'
end
Update . to the MyFramework.podspec location if needed.

How to link and use embedded framework with Swift and cocoapods?

My project include three target: App, Lib. Lib is depended on Alamofire via Cocoapod, and have umbrella header named Lib.h
Inside a swift source file of App target i use
import Lib
and compiler complain that
missing required module: 'Alamofire'
My podfile is something like this :
source 'https://github.com/CocoaPods/Specs.git'
workspace '../Myworkspace'
xcodeproj 'MyProject'
platform :ios, '8.0'
use_frameworks!
link_with 'Lib'
pod 'Alamofire'