运行pod安装时Flutter iOS构建失败

hs1ihplo  于 2023-02-09  发布在  Flutter
关注(0)|答案(8)|浏览(285)

我正在尝试做一个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
qrjkbowd

qrjkbowd1#

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

41ik7eoe

41ik7eoe2#

如果您使用的是Apple Silicon Chip(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
7hiiyaii

7hiiyaii3#

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

sudo arch -x86_64 gem install ffi

并运行:

arch -x86_64 pod install

代替

pod install
bvhaajcl

bvhaajcl4#

每次我把我的项目从一台电脑换到另一台电脑时,我都会遇到这个问题,
我按照这个步骤来解决这个问题,
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
4zcjmb1e

4zcjmb1e5#

您需要设置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 thread和这个stackoverflow讨论,以获得关于为什么会发生这种情况的更多细节。

v6ylcynt

v6ylcynt6#

我在项目级别名称SWIFT-VERSION上为Runner添加了一个用户定义的构建设置,其他设置都不起作用。

j91ykkif

j91ykkif7#

不用担心。有一个简单的解决方案。创建这个文件-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已设置完毕。

o2g1uqev

o2g1uqev8#

我跑:

pod repo update

并解决它

相关问题