Nativescript Algolia iOS构建失败

时间:2019-03-14 02:25:05

标签: nativescript angular2-nativescript nativescript-angular nativescript-plugin

我正在尝试构建nativescript-algolia,但在iOS上失败。这是我得到的错误:

[!] Unable to determine Swift version for the following pods:

- `AlgoliaSearch-Client-Swift` does not specify a Swift version 
and none of the targets (`appname`) integrating it have the 
`SWIFT_VERSION` attribute set. Please contact the author
or set the `SWIFT_VERSION` attribute in at least one of the 
targets that integrate this pod.

我已经尝试了从谷歌搜索这个问题中看到的一切。我似乎无法正确设置Swift版本。

3 个答案:

答案 0 :(得分:1)

Podfile中创建一个名为App_Resources/iOS的文件,并添加以下行,

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '4.0'
     end
   end
end

答案 1 :(得分:1)

在插件创建者的帮助下,我可以通过降级Cocoapods版本来解决此问题。

sudo gem uninstall cocoapods
sudo gem install cocoapods -v 1.5.3

参考文献:

https://github.com/arpit2438735/nativescript-algolia/issues/19#issuecomment-472847392

Swift Version NativeScript

答案 2 :(得分:1)

降级为1.5.3并不是一个适当的解决方法,将来也无法持续。实际上,此错误是由于Cocoapods 1.6.0版本中引入的新行为所致,该行为迫使开发人员为其项目设置Swift版本。实际上,目标是使库开发人员在其podspec中指定Swift版本,这样库用户就不必手动执行此操作(例如,感谢post_install脚本)。您可以看到my discussion about this with a Cocoapods maintainer here。我确实同意这种行为有点误导,因为我们尝试在post_install脚本中设置Swift版本,但是在……之前返回了错误。

实际上,正如维护人员告诉我的那样,此问题的正确解决方法是在项目级别(因此不在Pod级别)设置Swift版本。为此,只需在User Defined Setting中添加新的Build Settings,并使用键SWIFT_VERSION和值4.0(例如,如果您还设置了版本在post_install脚本的Pod级别)。

长话短说,解决方法是添加此键/值: enter image description here

请注意,在使用NativeScript时,您可能需要在构建之前通过在项目文件夹中运行命令export SWIFT_VERSION=4来设置Swift版本。