XCode14.3问题 2023-04-07 周五

简介

本来好好的,突然打包不行了,模拟器也不能用了,郁闷了好几天。后来才发现原来的是XCode14.3的问题,降级到XCode14.2,就正常了。

打包问题

企业微信截图_08c872a8-353f-467b-baba-2a5f14ba0751.png
  • 这里有用的信息不多,根据Command PhaseScriptExecution failed with a nonzero exit code去百度,得到的方案基本不靠谱

  • 去掉CocoaPods脚本执行,本地用没问题,但是提交苹果市场后就会有问题。


    企业微信截图_36ef3464-18b6-415d-b909-f258121bdf20.png
image.png

Xcode 14.3 is now using a relative path in its symlink for frameworks. Without the -f flag, this relative path would be evaluated relative to the working directory of the script being executed, instead of relative to the framework symlink itself. With the -f flag, it resolves that relative path and returns the full path to the source.

  • 提问的时候,CocoaPods的版本是1.11.3,我的MAC上已经升级到1.12.0,仍然无效。

如何解决?

把Pods -> Targets Support Files -> Pods-工程名字-frameworks.sh这个配置文件的44行,加个-f参数就好了

企业微信截图_b5cd1bb1-7394-4093-8502-3e1d60428e02.png

模拟器问题

编译都不过,第三方库直接就报错:

In /Users/zxs/git/ios/storage/Pods/YYImage/Vendor/WebP.framework/WebP(anim_decode.o), building for iOS Simulator, but linking in object file built for iOS, file '/Users/zxs/git/ios/storage/Pods/YYImage/Vendor/WebP.framework/WebP' for architecture arm64

解决方法

就是模拟器的时候,需要排除arm64芯片,需要在PodFile中添加以下内容:

# Fixed iOS simulator Link error for arm64 architecture on xCode 12.* for Apple M1 chip?
        # alse added on **** -> Build Settings -> Excluded architectures -> DebugStaging
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
      end
    end

自动添加-f参数的脚本

手动加个-f很简单,但是每次podinstall之后就会被改回去。这里有篇文章介绍在PodFile中用脚本自动改,可以试试。Podfile Xcode 13 readlink fix

post_install do |installer|
  project_path = "工程名字.xcodeproj"
  project = Xcodeproj::Project.open(project_path)
  project.targets.each do |target|
    shell_script_path = "Pods/Target Support Files/Pods-工程名字/Pods-"+target.name+"-frameworks.sh"
    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

降低版本

XCode14.3问题很多,XCode14.2表现稳定,所以可以下载一个XCode14.2备用。

  • 下载一个XCode14.2,解压之后改名为XCode_14.2,访问应用程序文件夹,和最新的XCode(14.3)共存。
企业微信截图_feacad76-6d95-4d74-b213-4193a273e259.png
  • 要解决打包的问题,需要进入Xcode_14.2才能解决。

关于Command Line Tools

网上有文章说,在XCode14.3的环境中,使用14.2的Command Line Tools来解决问题。

image.png
  • 经过试验,打包问题无法解决;但是Flutter工程模拟器无法运行的问题可以解决。
    大概的原因是Flutter是以命令行的方式调用XCode编译的。
企业微信截图_fff5254c-086b-4f5d-b0b3-9f83fb8244f5.png

这个问题可以通过设置XCode14.2命令行工具解决

小结

经过多方权衡,还是将XCode降级为14.2来解决问题比较好。

公司其他同事还没有升级,就别升级了,继续使用XCode14.2

参考文档

XCode升级14.3 archive打包失败

升级XCode14.3后,构建失败

iOS问题记录 - Xcode 14.3版本运行项目报错

后记

  • 一开始,下载 XCode14.2,保持2个版本共存;

  • 后来,感觉这个XCode14.3实在太差了,莫名其妙的问题太多,果断删除;

  • 苹果这些年是一年比一年差,XCode的问题一年比一年多,乔布斯才是苹果的灵魂;

  • 正式退回到XCode14.2,并且只保留这一个,删除恶心的XCode14.3;

  • 后续版本,要先看网络上的评价,才考虑是否升级。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容