Building Cocoapod library with GoogleMaps SDK - ios

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

Related

Podspec s.vendored_frameworks not working

Maybe I misunderstood the way of s.ios.vendored_frameworks work but I'm trying to use/integrate the Sinch.framework in my own SDK (for the voip part) but in my ReplaceMe.swift I'm not able to import or use any stuff from it
My hierarchy after I used s.ios.vendored_frameworks is the following
My podspec (last version of cocoapods is used)
s.ios.source_files = 'PoCSDK/Classes/**/*','PoCSDK/Frameworks/Sinch.frameworks/Headers/*'
s.ios.vendored_frameworks = 'PoCSDK/Sinch.framework'
s.ios.public_header_files = 'PoCSDK/Frameworks/Sinch.frameworks/Headers/*'
s.resource_bundles = {
'NoddsSDK' => ['PoCSDK/Assets/*']
}
s.frameworks = 'UIKit', 'MapKit', 'AudioToolbox', 'AVFoundation'
s.ios.dependency 'Alamofire', '~> 4.5'
s.ios.dependency 'Socket.IO-Client-Swift'
s.ios.dependency 'ReachabilitySwift'
What I did to add Fabric and Crashlytics to my development pod:
Create Frameworks folder in your Development pod folder
Copy your frameworks to the folder
Update your pod spec
s.vendored_frameworks = 'podname/Frameworks/Fabric.framework', 'podname/Frameworks/Crashlytics.framework'
s.preserve_path = 'podname/Frameworks/*'
Have you checked the real project structure in finder rather than those in Xcode?
Because I put my "Finder" path in vendored_frameworks and all worked for me.

Xcode Workspace - Not finding imports from framework development pod

I've set up a workspace with two Swift projects in it: one a framework I'm developing, the other a demo app for the framework.
Podfile looks like this:
platform :ios, '9.0'
workspace 'foo.xcworkspace'
target 'framework' do
project 'framework.xcodeproj'
end
target :'demo' do
project 'demo/demo.xcodeproj'
pod 'framework', :path => 'framework.podspec'
end
the .podspec file looks like this:
Pod::Spec.new do |s|
s.name = 'framework'
s.authors = { "foo author" }
s.version = '0.1.0'
s.summary = 'foo summary.'
s.homepage = 'foo homepage'
s.platform = :ios, '9.0'
s.license = {
:type => "Proprietary",
:file => "LICENSE"
}
s.source = {
:git => 'https://url.to/foo.git',
:tag => s.version.to_s
}
s.source_files = 'framework/framework/**/*.{swift,h,m}'
s.requires_arc = true
s.weak_framework = "XCTest"
s.pod_target_xcconfig = {
'FRAMEWORK_SEARCH_PATHS' => '$(inherited) "$(PLATFORM_DIR)/Developer/Library/Frameworks"',
}
end
After running pod install, Xcode/AppCode can still not see the classes from the framework project. So if I add a manual import to a class in the demo app and try to compile, it fails with:
Error:(13, 21) use of undeclared type 'FooClass'
What do I have to do to properly have the demo app project see the classes from the framework project generated pod?
Try using inherit! :search_paths on the demo target
This means they don't get their own copies of the pods but can see they exist via the header files.
platform :ios, '9.0'
workspace 'foo.xcworkspace'
target :framework do
project 'framework.xcodeproj'
end
target :demo do
inherit! :search_paths
project 'demo/demo.xcodeproj'
pod 'framework', :path => 'framework.podspec'
end
untested but perhaps worth a shot
If you install a Cocoapod don't use the file with .xcodeproj to open your project anymore, but the newly created .workspace in the same folder.
I finally resolved this issue:
Make sure the min. required iOS is defined in Podfile, e.g.:
platform :ios, '10.0'
Add any third-party pods also to the podspec file, e.g.:
spec.dependency 'Alamofire', '~> 4.5'
spec.dependency 'Serpent', '~> 1.0'
If doing pod install without the use_frameworks! it will mess up some things (see this answer: ld: framework not found Pods). So in between I got these invalid Pod xconfigs that I had to delete and then do a clean and pod install.
Make sure to build the framework project at least once and then the demo source should find the import to the framework pod name!
Make sure that all classes are correctly added to their target, especially classes in the test target should not have been added to the app target accidentally.
After all is said and done, having worked with a multitude of IDEs and development technologies, Xcode and Cocoapods can only be summed up as one giant clusterf*** of an accident!

Using CocoaPods with frameworks and static libraries at the same time

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.

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.

Attempting to add OpenTok 2.3 as a local cocoapod

I need to add OpenTok 2.3 to a project that uses cocoapods, however only 2.1.7 is present in the pods repository or on github, so I have downloaded the framework locally. My folder structure looks something like this:
project-
|
Podfile
project.xcodeproj
frameworks/
|
OpenTokSDK-WebRTC.podspec
OpenTok-iOS-2.3.0/
|
OpenTok.framework
And the contents of the OpenTokSDK-WebRTC.podspec file is:
Pod::Spec.new do |s|
s.name = 'OpenTokSDK-WebRTC'
s.version = '2.3'
s.authors = 'TokBox'
s.summary = 'The OpenTok iOS SDK lets you use OpenTok video sessions in apps you build for iPad, iPhone, and iPod touch devices.'
s.homepage = 'https://github.com/opentok/opentok-ios-sdk-webrtc/'
s.license = {
:type => 'Apache'
}
s.source = {
:path => './OpenTok-iOS-2.3.0'
}
s.platforms = {
:ios => '5.0'
}
s.source_files = 'Opentok.framework/Versions/A/Headers/*.h'
s.resources = 'Opentok.framework/Versions/A/Resources/opentok.bundle'
s.frameworks = [
"Opentok",
"UIKit",
"CoreMedia",
"CoreVideo",
"CoreAudio",
"CoreTelephony",
"CFNetwork",
"AVFoundation",
"SystemConfiguration",
"Security",
"QuartzCore",
"AudioToolbox",
"OpenGLES",
"MobileCoreServices"
]
s.libraries = [
"stdc++",
"z"
]
s.xcconfig = {
:FRAMEWORK_SEARCH_PATHS => "\"frameworks/OpenTokSDK-WebRTC/\""
}
s.preserve_paths = 'Opentok.framework'
s.requires_arc = false
end
The relevant line in the Podfile is
pod 'OpenTokSDK-WebRTC', :path => "frameworks"
When I run 'pod install' everything appears to run fine, however there is no OpenTokSDK folder in the Pods directory and I get a file not found error in xcode when trying to include . Does anyone know what I am missing?
Thanks for your help.
As I found on their Blog Here is the link new-in-ios-10-the-best-webrtc-apps-yet. you need to Add pod 'OpenTok' in your pod file. So updated version of talk box is Added in your Project. and Now Open your xcworkspace file inplace of xcodeproj file .
Here is my Podfile ,
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'ProjectName' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
pod 'AFNetworking', '~> 3.0'
pod 'OpenTok'
# Pods for ProjectName
target 'ProjectNameTest' do
inherit! :search_paths
# Pods for testing
end
target 'ProjectNameUITests' do
inherit! :search_paths
# Pods for testing
end
end
Note :- If you are using Swift then please uncomment # use_frameworks!
After updating your pod file enter "pod install" command in your terminal. and Tokbox will successfully install in your project.

Resources