运行 pod install 时 Flutter iOS 构建失败

Posted

技术标签:

【中文标题】运行 pod install 时 Flutter iOS 构建失败【英文标题】:Flutter iOS build fail on running pod install 【发布时间】:2019-07-21 13:42:47 【问题描述】:

我正在尝试制作一个颤振插件,所以我按照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 has 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

【问题讨论】:

【参考方案1】:

你需要设置你的 Swift 版本,因为flutter_plugin did not specify a Swift version by default

在你的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 *** 讨论,了解有关发生这种情况的更多详细信息。

【讨论】:

【参考方案2】:

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

【讨论】:

【参考方案3】:

通过将flutter和CocoaPods更新到最新版本然后运行以下命令来修复

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

【讨论】:

【参考方案4】:

别担心。有一个简单的解决方案。创建这个文件 - 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 已经设置好了。

【讨论】:

【参考方案5】:

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

【讨论】:

【参考方案6】:

我也遇到过这个问题。然后我意识到这是“pod install”的问题。并在这里找到了解决方案https://github.com/CocoaPods/CocoaPods/issues/10723

sudo arch -x86_64 gem install ffi

然后运行:

arch -x86_64 pod install

而不是

pod install

【讨论】:

以上是关于运行 pod install 时 Flutter iOS 构建失败的主要内容,如果未能解决你的问题,请参考以下文章

如何解决mac上flutter中的“error running pod install”?

Flutter 'Error running pod install' 'Pods-Runner' 目标具有传递依赖关系

Flutter ios pod install 更改部署目标

Flutter小记7​Mac M1 使用 pod install编译常见两种错误解决方案(CocoaPod Error | LoadError)

Flutter小记7​Mac M1 使用 pod install编译常见两种错误解决方案(CocoaPod Error | LoadError)

Flutter小记7​Mac M1 使用 pod install编译常见两种错误解决方案(CocoaPod Error | LoadError)