Xcode升级14.3.1版本报错问题

本文首发于公众号【一个老码农】

有大半年没有碰ios的代码了,前段时间有点小需求需要开发,正好借机把Xcode从14.0.1升级到了14.3.1。然后最担心的问题终于还是发生了,项目编译报错,而且是一系列的报错。今天有空记录一下

报错一

报错信息如下:

File not found: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphonesimulator.a

查询资料之后发现,是pods中的库支持版本过低导致的。需要把pods库的支持系统版本改为11.0。

我看了下项目中pods的第三方库支持的iOS版本有的是8.0的,有的是9.0的。而项目中app的支持版本早就改为了11.0以上。

现在有两种解决方法:

方案一

手动把podstarges里面的第三方库全部改为11.0,但是比较繁琐,而且执行pod install时容易再次被覆盖。

方案二

Podfile中添加如下脚本,然后执行pod install

arduino 复制代码
post_install do |installer|
  installer.generated_projects.each do |project|
    project.targets.each do |target|
      target.build_configurations.each do |config|
            config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
       end
    end
  end
end

报错二

执行完以上操作后,再次编译,真机编译成功了,但是模拟器编译报错,报错信息如下:

in /path/Pods/WechatOpenSDK/OpenSDK1.8.7.1/libWeChatSDK.a(WechatAuthSDK.o), building for iOS Simulator, but linking in object file built for iOS, file '/path/Pods/WechatOpenSDK/OpenSDK1.8.7.1/libWeChatSDK.a' for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

这个问题是因为以前的mac用的是intel的处理器,intel处理器是x86_64架构。而2020年以后苹果的m系列芯片电脑则使用的是arm64架构,所以使用新电脑会导致很多老项目代码编译报错。

解决方案:

  1. 第一步,找到Build Settings -> Excluded Architectures,添加一项Any iOS Simulator SDK,然后将其值设为arm64
  2. 第二步,将pod中的第三方库也设置为排除模拟器arm64指令,所以我在Podfile中的脚本就变成了这样:
arduino 复制代码
post_install do |installer|
  installer.generated_projects.each do |project|
    project.targets.each do |target|
      target.build_configurations.each do |config|
            config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
            config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = "arm64"
       end
    end
  end
end
  1. 执行pod install

报错三

做完以上操作之后,在archive打包时我又迎来了第三个报错:

Command PhaseScriptExecution failed with a nonzero exit code

解决方案如下:

方案一

全局搜索 source="$(readlink "${source}")" 替换成 source="$(readlink -f "${source}")",但是下次再执行pod install的时候有可能被覆盖

方案二

还是在Podfile中填加脚本,然后执行pod install。脚本如下:

arduino 复制代码
post_install do |installer|
  installer.generated_projects.each do |project|
    project.targets.each do |target|
      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
    end
  end
end

脚本合并

把以上三个脚本合并,我的Podfile中的脚本最终变成了这样:

arduino 复制代码
post_install do |installer|
    installer.generated_projects.each do |project|
          project.targets.each do |target|
            # 修改pod的target中的 source="$(readlink "${source}")" 替换成 source="$(readlink -f "${source}")"
            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
              target.build_configurations.each do |config|
                  config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
                  config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = "arm64"
               end
          end
   end
end

三个脚本合并后,执行pod install,然后再执行archive 操作,一切恢复正常

相关推荐
missmisslulu16 小时前
电容笔值得买吗?2024精选盘点推荐五大惊艳平替电容笔!
学习·ios·电脑·平板
GEEKVIP17 小时前
手机使用技巧:8 个 Android 锁屏移除工具 [解锁 Android]
android·macos·ios·智能手机·电脑·手机·iphone
GEEKVIP17 小时前
如何在 Windows 10 上恢复未保存/删除的 Word 文档
macos·ios·智能手机·电脑·word·笔记本电脑·iphone
奇客软件18 小时前
iPhone使用技巧:如何恢复变砖的 iPhone 或 iPad
数码相机·macos·ios·电脑·笔记本电脑·iphone·ipad
奇客软件2 天前
如何从相机的记忆棒(存储卡)中恢复丢失照片
深度学习·数码相机·ios·智能手机·电脑·笔记本电脑·iphone
GEEKVIP2 天前
如何修复变砖的手机并恢复丢失的数据
macos·ios·智能手机·word·手机·笔记本电脑·iphone
一丝晨光2 天前
继承、Lambda、Objective-C和Swift
开发语言·macos·ios·objective-c·swift·继承·lambda
GEEKVIP3 天前
iPhone/iPad技巧:如何解锁锁定的 iPhone 或 iPad
windows·macos·ios·智能手机·笔记本电脑·iphone·ipad
KWMax3 天前
RxSwift系列(二)操作符
ios·swift·rxswift
Mamong3 天前
Swift并发笔记
开发语言·ios·swift