6

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

7 回答 7

10

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

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

对于 Apple M1 芯片,只需卸载所有已cocoapods安装的gem,然后尝试安装brew

sudo gem uninstall cocoapods

brew install cocoapods

接着

 flutter clean
    rm -Rf ios/Pods
    rm -Rf ios/.symlinks
    rm -Rf ios/Flutter/Flutter.framework
    rm -Rf ios/Flutter/Flutter.podspec
于 2020-08-20T12:16:52.947 回答
3

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

于 2019-02-28T05:33:52.293 回答
2

你需要设置你的 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

您还可以查看github 线程和 stackoverflow 讨论,以了解有关此情况发生原因的更多详细信息。

于 2019-02-27T19:41:15.060 回答
1

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

于 2020-11-17T17:13:02.743 回答
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 已设置。

于 2020-09-19T05:36:34.403 回答
0

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

sudo arch -x86_64 gem install ffi

并运行:

arch -x86_64 pod install

代替

pod install
于 2021-12-16T09:17:20.053 回答
0

每次我将项目更改为另一台电脑时,我都会遇到这个问题,

我按照这个步骤来解决这个问题,

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.运行

flutter clean
flutter run
于 2022-02-22T09:01:17.510 回答