美文网首页
Mac下, Flutter项目在Xcode 14.3运行报错汇总

Mac下, Flutter项目在Xcode 14.3运行报错汇总

作者: Sam_xing | 来源:发表于2023-05-31 17:34 被阅读0次

开发环境

  • macOS Ventura 13.4
  • Xcode 14.3

Xcode 14.3 无法运行测试

   模拟器file not found: libarclite_iphonesimulator.a
   真机  file not found: libarclite_iphoneos.a

这个问题分为2方面解决:

  1. Xcode 14.3版本移除了内置ARC相关的库,从而导致一些默认部署目标是iOS 8版本的第三方库出现报错。只要最低部署目标不低于iOS 9版本,运行项目时就不会去链接ARC相关的库,也就不会出现找不到库的报错。
    在Podfile文件中添加
post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
        end
    end
end

2.有时候必须支持老版本, 不管用模拟器还是真机测试的时候, 仅仅是添加上述代码, 依然无法运行. 因此我们需要将未升级前的arc文件复制到Xcode 14.3
转至arc下载页
解压后复制到指定的目录路径:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib

Xcode 14.3 Command PhaseScriptExecution failed with a nonzero exit code

由于Pods-app-frameworks.sh编译时, 出现的问题

全局搜索
source="$(readlink "${source}")"
替换为
source="$(readlink -f "${source}")"

但是, 每当重新build的时候, 编译文件又回归原始, 因此我们可以在Podfile文件post_install do |installer|中添加

shell_script_path = "Pods/Target Support Files/#{target.name}/#{target.name}-frameworks.sh"
          if File::exists?(shell_script_path)
            shell_script_input_lines = File.readlines(shell_script_path)
            shell_script_output_lines = shell_script_input_lines.map { |line| line.sub("source=\"$(readlink \"${source}\")\"", "source=\"$(readlink -f \"${source}\")\"") }
            File.open(shell_script_path, 'w') do |f|
              shell_script_output_lines.each do |line|
                f.write line
              end
          end
        end

这样, 就会在build的时候, 自动替换.

post_install do |installer| 的一些变量

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 11.0
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
      end
      if config.name == 'Test'
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)','TEST=1']
        config.build_settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS'] = ['$(inherited)','TEST']
        config.build_settings['GCC_OPTIMIZATION_LEVEL'] = 0
        config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone'
      end
    end
  end
end
IPHONEOS_DEPLOYMENT_TARGET 库最低版本设置
GCC_PREPROCESSOR_DEFINITIONS 编译环境配置
SWIFT_ACTIVE_COMPILATION_CONDITIONS 编译环境配置
GCC_OPTIMIZATION_LEVEL oc编译优化级别
SWIFT_OPTIMIZATION_LEVEL swift编译级别优化

相关文章

网友评论

      本文标题:Mac下, Flutter项目在Xcode 14.3运行报错汇总

      本文链接:https://www.haomeiwen.com/subject/wquyedtx.html