Flutter插件iOS构建失败

时间:2019-02-27 18:26:30

标签: dart flutter

im试图制作一个插件,所以我按照https://flutter.dev/docs/development/packages-and-plugins/developing-packages上提供的步骤创建了一个插件。当我尝试运行ios示例时出现错误。以下是运行ios示例应用程序时获取的日志即时消息。 有人可以帮我吗?

Running pod install...
CocoaPods' output:
    Analyzing dependencies

    Inspecting targets to integrate
      Using `ARCHS` setting to build architectures of target `Pods-Runner`: (``)

    Fetching external sources
    -> Fetching podspec for `Flutter` from `.symlinks/flutter/ios`
    -> Fetching podspec for `flutter_plugin` from `.symlinks/plugins/flutter_plugin/ios`

    Resolving dependencies of `Podfile`

    Comparing resolved specification to the sandbox manifest
      A Flutter
      A flutter_plugin

    Downloading dependencies

    -> Installing Flutter (1.0.0)

    -> Installing flutter_plugin (0.0.1)
      - Running pre install hooks
    [!] Unable to determine Swift version for the following pods:

    - `flutter_plugin` does not specify a Swift version and none of the targets (`Runner`) 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.

    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/lib/cocoapods/installer/xcode/target_validator.rb:115:in `verify_swift_pods_swift_version'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/lib/cocoapods/installer/xcode/target_validator.rb:37:in `validate!'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/lib/cocoapods/installer.rb:459:in `validate_targets'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/lib/cocoapods/installer.rb:138:in `install!'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/lib/cocoapods/command/install.rb:48:in `run'
    /Library/Ruby/Gems/2.3.0/gems/claide-1.0.2/lib/claide/command.rb:334:in `run'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/lib/cocoapods/command.rb:52:in `run'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.6.1/bin/pod:55:in `<top (required)>'
    /usr/local/bin/pod:22:in `load'
    /usr/local/bin/pod:22:in `<main>'

Error output from CocoaPods:
        [33mWARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
        Consider adding the following to ~/.profile:
Error running pod install

5 个答案:

答案 0 :(得分:3)

通过将绒毛和可可豆荚更新到最新版本,然后

flutter clean
rm -Rf ios/Pods
rm -Rf ios/.symlinks
rm -Rf ios/Flutter/Flutter.framework
rm -Rf ios/Flutter/Flutter.podspec

答案 1 :(得分:1)

解决了问题..当我们在终端上通过命令创建插件时,它会使用Android的默认Java和iOS的Objective-C创建一个插件。可以使用命令将其更改为Android的Kotlin和iOS的Swift,但是它将仅对根文件夹中的andorid/ios/添加支持。这不会更改example/目录中的示例代码。所提供的示例仍然适用于Android的Java和iOS的Objective-C。因此,然后我从Android Studio创建了一个插件,通过选中“包括对iOS代码的Swift支持”选项创建了对iOS的Swift支持,它使用swift而不是Objective-C创建了一个示例。然后问题解决了。

答案 2 :(得分:0)

flutter_plugin did not specify a Swift version by default起,您需要设置Swift版本

在您的ios/Podfile中添加

config.build_settings['SWIFT_VERSION'] = '4.1'  # required by simple_permission

以以下方式:

target 'Runner' do
  use_frameworks!  # required by simple_permission
  ...
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '4.1'  # required by simple_permission
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end

您还可以查看this github线程和this stackoverflow讨论以获取有关发生这种情况的更多详细信息。

答案 3 :(得分:0)

不用担心。有一个简单的解决方案。创建此文件- AppResources / iOS / Podfile 并将其添加到文件中

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

就是这样,您的项目的SWIFT_VERSION已设置。

答案 4 :(得分:0)

我在项目级别名称SWIFT-VERSION上为Runner添加了用户定义的构建设置。没有其他东西对我有用。