我知道在SO上已经有关于此主题的一些问题,但是很少有人接受答案,而且我认为我没有发现与我完全相同的问题。
我正在构建一个Swift Pod,在我的代码中,我依赖于捆绑为.framework
文件的Google Maps iOS SDK 。该项目在Xcode中可以正常运行,但是我无法将库发布到Cocoapods。
我设法有了一个Podspec
几乎可以使用该pod lib lint
命令验证的文件。但是,既然我已经将Google-Maps-iOS-SDK
pod作为依赖项添加到Podspec
文件中,它将失败并显示以下消息:
$ pod lib皮棉
[!]“ Pods”目标具有包含静态二进制文件的传递依赖项:(/private/var/folders/n2/qyjfpk6n7zz_mngtwswlmsy00000gn/T/CocoaPods/Lint/Pods/Google-Maps-iOS-SDK/GoogleMaps.framework)
$
这是预期的吗?为什么我不能在自己的基于Swift的pod中添加Google Maps iOS SDK作为pod引用?
这是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
如果我没有将Google Maps iOS SDK作为依赖项包含在内,那么pod lib lint
桥接头会失败,并抱怨找不到它<GoogleMaps/GoogleMaps.h>
(找不到文件)。
我被卡住了,我不知道这是Cocoapods 0.36(还是Beta版)中的错误还是我做错了什么。
谢谢你的帮助!
我终于在SO上找到了另一个处理类似问题的线程:通过CocoaPods添加了iOS的Google Maps在Swift项目中的链接器错误。
看来,这些错误是由于Podspec文件错误(在Google Maps iOS SDK方面)以及Cocoapods 0.36 Beta中的错误共同导致的。
实际上,可以使用@fz。的修订版Google Maps Podspec文件来解决这些问题:https ://stackoverflow.com/a/28471830/145997 。另一篇对理解vendored_frameworks
设置的工作原理也很感兴趣的文章Podspec
是:http : //codereaper.com/blog/2014/creating-a-pod-with-crashreporter/。
因此,要在Pod项目中正确导入Google Maps iOS SDK,请首先使用以下命令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!
现在,我只需执行即可从我的Swift代码中引用Google Maps类import GoogleMaps
。而且,要分发Pod,我的最终结果Podspec
类似于以下内容:
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
现在,我可以在Xcode中启动新的iOS应用,并使用以下内容Podfile
链接到自己的Pod,而该Pod本身就是Google Maps iOS SDK的参考:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
pod 'MyPod'
use_frameworks! # do not forget this!
并不是那么容易,但是毕竟可行!不过,希望Google能够Podspec
为Swift开发打补丁。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句