问题关键词:
**ERROR | [BlocksKit/All] xcodebuild: /Users/****/Desktop/BlocksKit/BlocksKit/DynamicDelegate/Foundation/NSURLConnection+BlocksKit.m:351:14: error: 'initWithRequest:delegate:startImmediately:' is unavailable: not available on watchOS**
-
- ERROR | [BlocksKit/DynamicDelegate] xcodebuild: Returned an unsuccessful exit code. You can use --verbose for more information.
- NOTE | [BlocksKit/DynamicDelegate] xcodebuild: /Users/****/Desktop/BlocksKit/BlocksKit/DynamicDelegate/A2BlockInvocation.h:6:9: fatal error: 'BKDefines.h' file not found
正文
谈一下为什么需要发布私有pod,公司使用cocoapod依赖的github上面的BlocksKit。我们从BlocksKit's issue也能发现一直存在crash,而最新提交还是two years ago 。看来我们只能自己去修改了。所以打算在clone一个,改完时候重新发个版本到公司内的gitlab上,这样自己就方便维护和使用了。
不过在解决这两个问题没少花时间,所以希望能帮助有类似问题的同学,为他们提供一种解决方法。
主要有两个问题:
- 在clone完项目之后,自己先试试了
pod lib lint --verbose
发现这个工程有问题,lint不过,提示的错误是:
……
- ERROR | [BlocksKit/All] xcodebuild: /Users/****/Desktop/BlocksKit/BlocksKit/DynamicDelegate/Foundation/NSURLConnection+BlocksKit.m:351:14: error: 'initWithRequest:delegate:startImmediately:' is unavailable: not available on watchOS
……
说是不支持watchOS,我点进去看了看initWithRequest:delegate:startImmediately
方法,发现确实标有__WATCHOS_PROHIBITED
- (nullable instancetype)initWithRequest:(NSURLRequest *)request delegate:(nullable id)delegate startImmediately:(BOOL)startImmediately NS_DEPRECATED(10_5, 10_11, 2_0, 9_0, "Use NSURLSession (see NSURLSession.h)") __WATCHOS_PROHIBITED;
本身我的工程就不是在watchOS上运行的,那就不让它支持watchOS好了。可是在哪设置能不让他支持watchOS呢?
我先是试了试删掉一些target,发现不能解决问题,最后在.podspec
文件下找到了可以设置是否支持watchOS的原因,下面是.podspec的部分代码
Pod::Spec.new do |s|
s.name = 'BlocksKit'
s.version = '2.2.6'
s.license = 'MIT'
……
s.osx.deployment_target = '10.8'
s.ios.deployment_target = '6.0'
s.watchos.deployment_target = '2.0'
……
end
就把s.watchos.deployment_target = '2.0'
这一行给删掉了,重新执行 pod lib lint
发现这个问题解决,欣喜中……
- 迎来了第二个问题,
- ERROR | [BlocksKit/DynamicDelegate] xcodebuild: Returned an unsuccessful exit code. You can use `--verbose` for more information.
- NOTE | [BlocksKit/DynamicDelegate] xcodebuild: /Users/****/Desktop/BlocksKit/BlocksKit/DynamicDelegate/Foundation/NSCache+BlocksKit.h:6:9: fatal error: 'BKDefines.h' file not found
- NOTE | [BlocksKit/DynamicDelegate] xcodebuild: /Users/****/Desktop/BlocksKit/BlocksKit/DynamicDelegate/A2DynamicDelegate.h:6:9: fatal error: 'BKDefines.h' file not found
- NOTE | [BlocksKit/DynamicDelegate] xcodebuild: /Users/****/Desktop/BlocksKit/BlocksKit/DynamicDelegate/A2BlockInvocation.h:6:9: fatal error: 'BKDefines.h' file not found
从上面的信息我们能看到BlocksKit/DynamicDelegate
这个子pod有问题。还是占一个完整的.podspec
文件吧:
Pod::Spec.new do |s|
s.name = 'BlocksKit'
s.version = '2.2.6'
s.license = 'MIT'
s.summary = 'The Objective-C block utilities you always wish you had.'
s.homepage = 'https://zwaldowski.github.io/BlocksKit'
s.author = { 'Zachary Waldowski' => '[email protected]',
'Alexsander Akers' => '[email protected]' }
s.source = { :git => ' https://github.com/zwaldowski/BlocksKit.git', :tag => "v#{s.version}" }
s.requires_arc = true
s.osx.deployment_target = '10.8'
s.ios.deployment_target = '6.0'
s.default_subspec = 'All'
s.subspec 'All' do |ss|
ss.dependency 'BlocksKit/Core'
ss.dependency 'BlocksKit/DynamicDelegate'
ss.ios.dependency 'BlocksKit/MessageUI'
ss.ios.dependency 'BlocksKit/QuickLook'
ss.ios.dependency 'BlocksKit/UIKit'
end
s.subspec 'Core' do |ss|
ss.source_files = 'BlocksKit/BlocksKit.h', "BlocksKit/BKDefines.h", 'BlocksKit/Core/*.{h,m}'
end
s.subspec 'DynamicDelegate' do |ss|
ss.source_files = 'BlocksKit/DynamicDelegate/*.{h,m}', 'BlocksKit/DynamicDelegate/Foundation/*.{h,m}'
end
s.subspec 'MessageUI' do |ss|
ss.dependency 'BlocksKit/Core'
ss.dependency 'BlocksKit/DynamicDelegate'
ss.platform = :ios
ss.source_files = 'BlocksKit/BlocksKit+MessageUI.h', 'BlocksKit/MessageUI/*.{h,m}'
ss.ios.frameworks = 'MessageUI'
end
s.subspec 'QuickLook' do |ss|
ss.dependency 'BlocksKit/Core'
ss.dependency 'BlocksKit/DynamicDelegate'
ss.platform = :ios
ss.source_files = 'BlocksKit/BlocksKit+QuickLook.h', 'BlocksKit/QuickLook/*.{h,m}'
ss.ios.frameworks = 'QuickLook'
end
s.subspec 'UIKit' do |ss|
ss.dependency 'BlocksKit/Core'
ss.dependency 'BlocksKit/DynamicDelegate'
ss.platform = :ios
ss.source_files = 'BlocksKit/BlocksKit+UIKit.h', 'BlocksKit/UIKit/*.{h,m}'
end
end
这次我们能看到是BlocksKit/DynamicDelegate
这个subspec的问题了吧。发现这个subspec的source_files是'BlocksKit/DynamicDelegate/*.{h,m}', 'BlocksKit/DynamicDelegate/Foundation/*.{h,m}'
这些。我们从工程结构里看,下面是工程结构的截图:
可以看到出错的就是这几个文件,找不到.h文件,我试了试在buildSettings里面添加headerpath,发现没有用。翻遍了cocoapods的issues和Stack Overflow中cocoapod专栏,发现没找着原因。
最后突然发现,哎,这个
BKDefines.h
不是在
core
这个subspec中吗,有没有可能是因为
'DynamicDelegate'
这个subspec没有依赖
core
这个pod呢!想到这,就赶紧翻看了上面
.podspec
文件,发现真的是没引用。于是我就在
DynamicDelegate
下加了对
core
的依赖。如下:
s.subspec 'DynamicDelegate' do |ss|
ss.source_files = 'BlocksKit/DynamicDelegate/*.{h,m}', 'BlocksKit/DynamicDelegate/Foundation/*.{h,m}'
ss.dependency 'BlocksKit/Core' //新加了这行
end
重新执行pod lib lint
通过,就能够lint通过了。大功告成