Using CocoaPods with frameworks and static libraries at the same time - ios

I have this Podfile in my project:
platform :ios, '8.0'
use_frameworks!
target 'FunnyApp' do
pod 'Alamofire', '~> 1.2'
pod 'SWXMLHash', '~> 1.0'
pod 'VaultKit', :path => './Frameworks/VaultKit'
pod 'SessionKit', :path => './Frameworks/SessionKit'
end
Only VaultKit is static library written in Objective-C. It has this podspec:
Pod::Spec.new do |s|
s.name = 'VaultKit'
s.version = '0.1'
s.license = 'MIT'
s.summary = 'Encryption library'
s.homepage = 'https://someurl.com'
s.social_media_url = 'http://twitter.com/greenfish29'
s.authors = { 'Tomas Sliz' => 'greenfish29#email.com' }
s.source = { :git => 'git#github.org:greenfish29/vaultkit.git' }
s.ios.deployment_target = '8.0'
s.public_header_files = 'VaultKit/VaultKit.h'
s.source_files = "VaultKit/*.{h,m}" "VaultKit/Models/*.{h,m}"
s.requires_arc = true
end
I have bridging header in my project too with this record:
#import <VaultKit/VaultKit.h>
But when I try to build project, I get this error:
FunnyApp-Bridging-Header.h:5:9: 'VaultKit.h' file not found
What can be wrong?

Cocoapods doesn't support both Frameworks and Static libraries and neither they have an intention to do so.
See the discussion here.
I ended up using Obj-C only libraries for my project by using the bridging header because an important library which I couldn't do without had only an Obj-C version.
I think we may at least get support for dynamic frameworks which use static libraries as dependency in the future.

Related

How to add a .framework (done in obj-c) inside a swift pod lib

I am trying to include a .framework inside my pod project done in swift.
I have included it in my .podspec using "s.vendored_frameworks" like this:
Pod::Spec.new do |s|
s.name = 'Core'
s.version = '0.1.8'
s.summary = 'This is a pod with a MVVM skeleton that helps to start swiftUI projects'
s.ios.deployment_target = '14.0'
s.swift_versions = '5.2'
s.source_files = 'Core/Classes/**/*'
s.resource_bundles = {
'TGCore' => ['Core/Assets/*']
}
s.vendored_frameworks = 'Core/Frameworks/ScaleBleManagerSDK.framework'
s.resources = "Core/Assets/*"
s.frameworks = 'SwiftUI', 'Foundation'
s.dependency 'Moya', '<= 15.0.0-alpha.1'
end
ScaleBleManagerSDK.framework has been done in objective-c. In my podfile I added
use_frameworks!
So, when I try to use ScaleBleManagerSDK inside my development pod by creating a function I cannot access any of the headers of the framework I did import in the podspec.
What I need to do to access to the headers?
make sure that your headers are put in target -> build phrases -> headers -> public

Using the framework from one target as a pod in another target locally

I'm having trouble using a framework I wrote in other targets (the same project) using modular imports. I'm using Cocoapods. I'm getting Could not build module: errors while trying to import the module using modular imports (#import CMPComapiFoundation;). I attach a link to the repo for more information.
I did try both local (:path =>) and remote (:git =>) ways of pulling the SDK in Podfile, none of which seems to work. It's worth noting that if added via Cocoapods in a separate project, the code compiles and the SDK can be imported.
SDK's .podspec file:
Pod::Spec.new do |s|
s.name = 'CMPComapiFoundation'
s.version = '1.2.2'
s.license = 'MIT'
s.summary = 'Foundation library for connecting to and consuming COMAPI services'
s.description = <<-DESC
# iOS SDK for Comapi
Client to connect your iOS application with [Comapi](http://comapi.com/) services and add it as a channel to our cloud messaging platform. Written in Objective-C.
For more information about the integration please visit [the website](http://docs.comapi.com/reference#one-sdk-ios).
DESC
s.homepage = 'https://github.com/comapi/comapi-sdk-ios-objc'
s.author = { 'Comapi' => 'support#comapi.com' }
s.source = { :git => 'https://github.com/comapi/comapi-sdk-ios-objc.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/comapimessaging'
s.ios.deployment_target = '10.0'
s.requires_arc = true
s.source_files = 'Sources/**/*.{h,m}'
s.resources = []
s.dependency 'SocketRocket'
end
And here's the Podfile I'm using for the entire project:
platform :ios, '10.0'
use_frameworks!
def shared
pod 'CMPComapiFoundation', :path => '/Users/dominik.kowalski/Documents/comapi-sdk-ios-objc'
pod 'JWT'
end
target 'CMPComapiFoundation' do
pod 'SocketRocket'
end
target 'CMPComapiFoundationTests' do
shared
end
target 'ComapiFoundationSample' do
shared
end
target 'ComapiFoundationSample-Swift' do
shared
pod 'SnapKit'
end
I expect the test and sample targets to import the modules and compile the code.
Okay I managed to fix it myself. Some header files were missing Target membership, but Xcode gave me misleading hints.

Building Cocoapod library with GoogleMaps SDK

I want to use GoogleMaps in My Cocoapod library.
There is GoogleMaps in cocoapod. but, you can't use dependency because it is static library. probably...
I referenced this answer.
Building a Cocoapod with Swift and dependency on Objective-C framework
And, building library was succeeded.
I have problem when using builded library in Example project.
When I built Example project, first problem is
ld: framework not found GoogleMaps for architecture arm64
And, I tried to add GoogleMaps to Example project's Podfile.
next problem is
The 'Pods-MapLibraryWrapper_Example' target has frameworks with
conflicting names: GoogleMaps.
Is there a way to solve the problem? or, Is there a other way to use GoogleMaps?
Thanks.
Part of My library's podspec.
s.platform = :ios, '8.0'
s.requires_arc = true
s.source_files = 'Pod/Classes/**/*'
s.resource_bundles = {
'MapLibraryWrapper' => ['Pod/Assets/*.png']
}
s.ios.resource_bundle = { 'MapLibraryWrapper-ios' => 'Resources/*.png' }
s.public_header_files = 'Pod/Classes/**/*.h'
s.frameworks = "Accelerate", "AVFoundation", "CoreData", "CoreLocation", "CoreText", "Foundation", "GLKit", "ImageIO", "OpenGLES", "QuartzCore", "SystemConfigurati\
on", "GoogleMaps"
# s.dependency 'GoogleMaps'
s.libraries = "c++", "icucore", "z"
s.vendored_frameworks = 'Dependencies/GoogleMaps.framework'
s.prepare_command = './download-googlemaps.sh'
directory structure
$(project_root)
|- MapLibraryWrapper.podspec
|- Dependencies/
|- GoogleMaps.framework
|- Example
|- Podfile
Example/Podfile
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target 'MapLibraryWrapper_Example', :exclusive => true do
pod 'MapLibraryWrapper', :path => '../'
pod 'GoogleMaps'
end
target 'MapLibraryWrapper_Tests', :exclusive => true do
pod 'MapLibraryWrapper', :path => '../'
pod 'Quick', '~> 0.8.0'
pod 'Nimble', '3.0.0'
end

Framework header files not included in pod lib lint

I am trying to add VPX framework that is required for toxav to be compiled. I have my pod spec file like so:
Pod::Spec.new do |s|
s.name = "toxcore-ios"
s.version = "0.1.3"
s.summary = "Cocoapods wrapper for toxcore"
s.homepage = "https://github.com/dvor/toxcore-ios"
s.license = 'GPLv3'
s.author = { "Dmytro Vorobiov" => "d#dvor.me" }
s.source = {
:git => "https://github.com/dvor/toxcore-ios.git",
:tag => s.version.to_s,
:submodules => true
}
s.platform = :ios, '7.0'
s.requires_arc = true
s.source_files = 'toxcore/toxcore/*.{c,h}', 'toxcore/toxencryptsave/*.{c,h}', 'toxcore/toxav/*.{c,h}'
s.public_header_files = 'toxcore/toxcore/*.h', 'toxcore/toxav/*.h'
s.dependency 'libsodium', '~> 1.0.1'
s.dependency 'libopus', '~> 1.1'
s.ios.vendored_frameworks = 'VPX.framework'
s.prepare_command = 'libvpx/build/make/iosbuild.sh'
end
For what it's worth, the prepare_command creates the VPX.framework. I tried adding the VPX.framework files to the s.source_files and s.public_header_files, however they still receive the same error below when running pod lib lint. I'm not even sure if it's necessary to add it to the s.source_files or s.public_header_files since I believe the s.ios.frameworks already takes care of that?
toxcore/toxav/toxav.h:34:10: fatal error: 'vpx/vpx_image.h' file not found
I came across the same issue this week while linking frameworks in my newly created pod. You should use the --use-libraries option while using lint:
pod lib lint --use-libraries
This option is also available while pushing your pod to the master Cocoapods repository or your own repository.
pod repo push REPO_NAME POD_NAME.podspec --use-libraries
Hope this helps!
I figured out my issue. The VPX framework path was listed as below:
VPX.framework/Headers/vpx/{files.h}
When we use vendored_frameworks it actually only looks under the Header folder for the header files. So instead we had this
VPX.framework/Headers/{looks here}
In which case I had to move the files under vpx , to Header

Building a Cocoapod with Swift and dependency on Objective-C framework

I know there are already a few questions on this theme here on SO, but very few have accepted answers, and I don't think I have found the exact same problem as mine.
I'm building a Swift pod, and in my code I rely on the Google Maps iOS SDK, which is bundled as a .framework file. The project builds OK in Xcode, however I have troubles publishing the lib to Cocoapods.
I managed to have a Podspec file that almost validates using the pod lib lint command. However, now that I've added the Google-Maps-iOS-SDK pod as a dependency in the Podspec file, it fails with the following message:
$ pod lib lint
[!] The 'Pods' target has transitive dependencies that include static
binaries:
(/private/var/folders/n2/qyjfpk6n7zz_mngtwswlmsy00000gn/T/CocoaPods/Lint/Pods/Google-Maps-iOS-SDK/GoogleMaps.framework)
$
Is this expected? Why can't I add the Google Maps iOS SDK as a pod reference in my own Swift-based pod?
Here's the Podspec:
Pod::Spec.new do |s|
s.name = '(name)'
s.version = '1.0.0'
s.summary = '(summary)'
s.platforms = { :ios => '8.0', :osx => '10.10' }
s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.10'
s.license = { :type => 'BSD', :file => 'LICENSE' }
s.source_files = 'Sources/*.{h,swift}', '*.framework'
s.source = { :git => "https://github.com/(Github repo).git", :tag => "1.0.0" }
s.requires_arc = true
s.frameworks = "Foundation", "CoreLocation"
s.author = { 'Romain L' => '(email)' }
s.dependency 'Google-Maps-iOS-SDK'
end
If I don't include the Google Maps iOS SDK as a dependency, then pod lib lint fails in the Bridging Header, and complains it cannot find <GoogleMaps/GoogleMaps.h> (file not found).
I'm stuck, and I don't know if it's a bug from Cocoapods 0.36 (still in Beta) or if I'm doing something wrong.
Thanks for your help!
I finally found another thread on SO dealing with similar problems: Linker errors in a Swift project with Google Maps for iOS added via CocoaPods.
It appears that the errors were due to a combination of bad Podspec file (on the Google Maps iOS SDK side), and bugs in Cocoapods 0.36 Beta.
It's actually possible to workaround the issues by using #fz.'s revised Podspec file for Google Maps: https://stackoverflow.com/a/28471830/145997. Another article that also was of great interest to understand how the vendored_frameworks setting works in Podspec is: http://codereaper.com/blog/2014/creating-a-pod-with-crashreporter/.
So, to correctly import the Google Maps iOS SDK in a Pod project, first use the following Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
# altered version of Google's Podspec
pod 'Google-Maps-iOS-SDK', :podspec => "https://raw.githubusercontent.com/Reflejo/GoogleMapsPodspec/master/Google-Maps-iOS-SDK.podspec.json"
use_frameworks! # don't forget this!
I'm now able to reference Google Maps classes from my Swift code simply by doing import GoogleMaps. And, to distribute the Pod, my final Podspec now resembles the following:
Pod::Spec.new do |s|
s.name = 'MyPod'
s.version = '1.0.0'
s.homepage = "https://github.com/..."
s.summary = '(pod summary)'
#s.screenshot = ""
s.author = { 'Romain L' => '(email)' }
s.license = { :type => 'BSD', :file => 'LICENSE' }
s.social_media_url = "https://twitter.com/_RomainL"
s.platforms = { :ios => '8.0' }
s.ios.deployment_target = '8.0'
s.source_files = 'MyCode/*.{h,swift}'
s.module_name = 'MyPod'
s.source = { :git => "https://github.com/....git", :tag => "1.0.0" }
s.requires_arc = true
s.libraries = "c++", "icucore", "z" # required for GoogleMaps.framework
s.frameworks = "AVFoundation", "CoreData", "CoreLocation", "CoreText", "Foundation", "GLKit", "ImageIO", "OpenGLES", "QuartzCore", "SystemConfiguration", "GoogleMaps" # required for GoogleMaps.framework
s.vendored_frameworks = "Dependencies/GoogleMaps.framework" # Put the Google-provided framework in that subfolder of your Pod project
#s.dependency 'Google-Maps-iOS-SDK' # Careful! this will cause errors if enabled!
end
I am now able to start a new iOS app in Xcode and use the following Podfile to link against my own pod, itself referencing the Google Maps iOS SDK:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
pod 'MyPod'
use_frameworks! # do not forget this!
Not that easy, but feasible after all! Hoping Google will soon patch its Podspec file for Swift developments, though.

Resources