Flutter在运行pod install时,在iOS构建中失败

9
我尝试制作一个Flutter插件,所以我按照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
9个回答

7
如果你使用的是苹果硅芯片(M1),你可以这样做。
pod cache clean --all
Pod clean
pod deintegrate
sudo gem install cocoapods-deintegrate cocoapods-clean

sudo arch -x86_64 gem install ffi
arch -x86_64 pod repo update
arch -x86_64 pod install

7

遇到了问题。当我们在终端上使用命令创建插件时,默认情况下它会为Android创建一个Java插件,为iOS创建一个Objective-C插件。可以通过使用指令将其更改为Android的Kotlin和iOS的Swift,但这只会添加对根文件夹中的android/ios/的支持。这不会更改example/目录中的示例代码。提供的示例仍然是针对Android的Java或者iOS的Objective-C编写的。所以我从Android Studio创建了一个插件,勾选了“包括iOS代码的Swift支持”的选项,这样就创建了一个用Swift而不是Objective-C的示例。然后问题就解决了。


6

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

sudo arch -x86_64 gem install ffi

执行以下命令:

arch -x86_64 pod install

取代

pod install

4
每次我将项目从一台电脑转移到另一台电脑时,都会遇到这个问题,
我按照以下步骤解决了这个问题:
1.
Delete podfile.lock

2.替换这个

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end

使用

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
    end
    flutter_additional_ios_build_settings(target)
  end
end

3.run

flutter clean
flutter run

谢谢,这对我有用。如果你在从git推送和拉取代码时遇到这个bug,试试这个解决方案。快速而高效。 - Trịnh Đức Duy

1

您需要设置Swift版本,因为flutter_plugin默认没有指定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的Stack Overflow讨论,以获取有关为什么会发生这种情况的更多详细信息。


1

我为项目级别的Runner添加了一个名为SWIFT-VERSION的用户定义构建设置。对我来说,没有其他方法可行。


0
这通常发生在Apple Silicon上。 为了解决将来的问题。
1. 打开vim ~/.zshrc 2. 在你的zsh根目录下添加别名,例如cleanpods,alias pods='rm -rf ios/Pods && rm -rf ios/.symlinks && rm -rf ios/Flutter/Flutter.podspec && rm -rf ios/Podfile.lock && flutter clean && flutter pub get && cd ios && sudo arch -x86_64 gem install ffi && arch -x86_64 pod install && arch -x86_64 pod repo update && cd ..',然后按ESC键退出并保存vim,输入:wq!。 3. 只需运行cleanpods来解决当前和将来的问题。

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 已经设置好了。


0

我运行:

  pod repo update

并解决它


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接