用Swift构buildCocoapod并依赖于Objective-C框架
我知道在这方面已经有几个关于这个主题的问题了,但是很less有人接受答案,我不认为我发现了和我一样的问题。
我正在构build一个Swift窗格,在我的代码中,我依赖于Google Maps iOS SDK,它被捆绑为一个.framework
文件。 该项目在Xcode中生成确定,但是我有麻烦发布lib到Cocoapods。
我设法有一个Podspec
文件几乎validation使用pod lib lint
命令。 但是,现在我已经在Podspec
文件中添加了Google-Maps-iOS-SDK
pod作为依赖Podspec
,它将失败并显示以下消息:
$ pod lib lint
[Pod]目标具有包含静态二进制文件的传递依赖关系:(/ private / var /
$
这是预期的吗? 为什么我不能在我自己的基于Swift的窗格中添加Google Maps iOS SDK作为窗格参考?
这是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>
(文件未find)。
我卡住了,我不知道这是从Cocoapods 0.36(仍然在testing版)的错误,或者如果我做错了什么。
谢谢你的帮助!
我终于find了另外一个线程来处理类似的问题: 通过CocoaPods添加Google Maps for iOS的Swift项目中的链接器错误 。
看来,这些错误是由于糟糕的Podspec文件(在Google Maps iOS SDK一侧)以及Cocoapods 0.36 Beta中的错误导致的。
实际上可以通过使用@ fz。经修订的适用于Google地图的Podspec文件来解决这些问题: https ://stackoverflow.com/a/28471830/145997。 另外一篇文章也非常有趣,它可以帮助你理解“ vendored_frameworks
”中的vendored_frameworks
设置是如何工作的: http : Podspec
。
因此,要正确导入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!
我现在可以简单地通过import GoogleMaps
从我的Swift代码中引用Google Maps类。 而且,为了分发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,它本身引用了Google Maps iOS SDK:
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' pod 'MyPod' use_frameworks! # do not forget this!
不是那么容易,但毕竟是可行的! 希望Google尽快为Swift开发补丁Podspec
文件。