解决Xcode15调试iOS14设备crash的问题

1,021 阅读1分钟

升级Xcode15以后发现原本在Xcode14下正常运行的项目DEBUG调试时会crash,调试设备为iOS14系统的真机设备。

crash调用栈:

image.png

查询Xcode15 Release Notes后发现有列出此问题:

image.png

另外此问题官方在Xcode15.1 Beta2中已标记为已解决状态

image.png

解决方案

通过查询文档,苹果给了两个解决方案:

  • 修改构建目标版本到iOS15及以上版本
  • Build Settings下的Other Linker Flags增加 -Wl -ld_classic

第一个方案目前不太适合我们的项目,于是选择了第二个方案。

1、在项目的Podfile文件中增加以下代码

post_install do |installer|
  installer.generated_projects.each do |project|
    project.targets.each do |target|
        target.build_configurations.each do |config|
            # 解决Xcode15调试iOS14设备闪退的问题,此处只有Debug模式生效要是想在Debug、Release模式下都生效去掉此判断条件。
            if config.name.eql?('Debug')
              xcconfig_path = config.base_configuration_reference.real_path
              xcconfig = File.read(xcconfig_path)
              new_xcconfig = xcconfig.sub('OTHER_LDFLAGS = $(inherited)', 'OTHER_LDFLAGS = $(inherited) -Wl -ld_classic')
              File.open(xcconfig_path, "w") { |file| file << new_xcconfig }
            end
         end
    end
  end
end

2、在项目的Build Settings下的Other Linker Flags增加 -Wl -ld_classic

参考地址:stackoverflow