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

Amo*_*are 5 ios dart flutter flutter-plugin flutter-build

我正在尝试制作一个 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
Run Code Online (Sandbox Code Playgroud)

Alp*_*per 12

如果您使用的是 Apple Silicon Chip (M1),则可以执行此操作。

cd ios
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
Run Code Online (Sandbox Code Playgroud)


Par*_*iya 8

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

flutter clean
rm -Rf ios/Pods
rm -Rf ios/.symlinks
rm -Rf ios/Flutter/Flutter.framework
rm -Rf ios/Flutter/Flutter.podspec
Run Code Online (Sandbox Code Playgroud)


Amo*_*are 7

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


小智 7

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

sudo arch -x86_64 gem install ffi
Run Code Online (Sandbox Code Playgroud)

并运行:

arch -x86_64 pod install
Run Code Online (Sandbox Code Playgroud)

代替

pod install
Run Code Online (Sandbox Code Playgroud)