【问题标题】:Flutter - SWIFT_VERSION must be set to a supported valueFlutter - SWIFT_VERSION 必须设置为支持的值
【发布时间】:2018-10-31 16:24:03
【问题描述】:

尝试库 simple_permission,修复了 pod 错误,但出现了这个问题,不知道如何继续。 Build Settings中没有设置swift版本的设置,我尝试添加了,但是没有用。

Launching lib/main.dart on iPhone X in debug mode...
Skipping compilation. Fingerprint match.
Running Xcode clean...
Starting Xcode build...
Xcode build done.
Failed to build iOS app
Error output from Xcode build:
↳
** BUILD FAILED **

Xcode's output:
↳
=== BUILD TARGET simple_permissions OF PROJECT Pods WITH CONFIGURATION             Debug ===
    The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. This setting can be set in the build settings editor.
Could not build the application for the simulator.
Error launching application on iPhone X.

【问题讨论】:

    标签: ios flutter


    【解决方案1】:

    在文件 ios/XX.podspec 中添加这个

    s.swift_versions = ['4.0', '4.2', '5.0']
    

    这将消除错误。

    【讨论】:

      【解决方案2】:

      在这种情况下,必须创建桥接头。

      1. 使用 XCode 打开项目。然后选择文件 -> 新建 -> 文件 -> Swift 文件。创建 swift 时将显示一个对话框 文件(由于该文件已被删除,因此可以使用任何名称。)。 XCode 将 询问您是否要创建桥接头,单击是。 (它是 主要步骤)

      2. 确保您有 use_frameworks!在 Runner 块中,在 ios/Podfile 中。

      3. 确保在 XCode 中选择了 SWIFT_VERSION 4.2 -> 构建设置

      4. 做flutter clean

      5. 进入你的ios文件夹,删除Podfile.lock和Pods文件夹,然后执行pod install --repo-update

      【讨论】:

        【解决方案3】:

        通过在项目中创建一个空的 swift 文件来修复。

        【讨论】:

        • 这听起来很疯狂,但它确实有效(可能是因为它创建了一个桥接头)
        【解决方案4】:

        在其他答案对您不起作用的奇怪情况下,请使用pre_install,例如:

        pre_install do |installer|
          installer.analysis_result.specifications.each do |s|
            s.swift_version = '4.2' unless s.swift_version
          end
        end
        

        上面的答案和这个答案的组合肯定会解决这个问题。

        【讨论】:

          【解决方案5】:

          检查this answer

          当插件的 iOS 部分使用 Swift 编码时,您必须对 ios/Podfile 进行更改。您必须添加use_frameworks!config.build_settings['SWIFT_VERSION'] = '4.1'

          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
          

          您可以检查需要哪个SWIFT_VERSION,在that issue 中,使用3.2 解决了问题。在我发布的答案中,建议使用 4.1,但也可以使用 4.0。

          【讨论】:

            【解决方案6】:

            看看这个问题: https://github.com/flutter/flutter/issues/16049

            它帮助我在一个没有添加快速功能的项目中克服了这个问题,然后添加了地理定位插件。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2019-01-15
              • 2010-10-24
              • 1970-01-01
              • 1970-01-01
              • 2010-11-15
              • 2021-02-18
              • 2021-09-14
              相关资源
              最近更新 更多