Xcode 14.3 cocoapod 1.12.0 打包报错解决

前言

前几天升级Xcode到14.3版本,运行项目报错,于是记录下来。

开发环境

macOS: 13.3.1
Xcode: 14.3
CocoaPods: 1.12.0

问题描述

[Xcode菜单栏] -> [Product] -> [Archive],进行打包操作。执行到 Run custom shell script '[CP] Embed Pods Frameworks'时报错,报错相关日志如下:

Symlinked...

rsync --delete -av --filter P .*.?????? --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "../../../IntermediateBuildFilesPath/UninstalledProducts/iphoneos/xxx.framework" "/Users/xxx/Library/Developer/Xcode/DerivedData/app-dukdzczlzijlklamofogqicmtktj/Build/Intermediates.noindex/ArchiveIntermediates/app/InstallationBuildProductsLocation/Applications/app.app/Frameworks"

building file list ... rsync: link_stat "xxx/../../../IntermediateBuildFilesPath/UninstalledProducts/iphoneos/xxx.framework" failed: No such file or directory(2)

rsync error: some files could not be transferred (code 23) at /AppleInternal/Library/BuildRoots/97f6331a-ba75-11ed-a4bc-863efbbaf80d/Library/Caches/com.apple.xbs/Sources/rsync/rsync/main.c(996) [sender=2.6.9]

Command PhaseScriptExecution failed with a nonzero exit code

如图:
报错截图
在网上搜索找到一种解决办法:说这是一个 cocoapods 问题:https://developer.apple.com/forums/thread/727525https://github.com/CocoaPods/CocoaPods/pull/11828#issuecomment-1497329930
需要修改的是,进入pod文件的 “Pods-APPNAME-frameworks.sh” 文件:

原码:

if [ -L "${source}" ]; then
    echo "Symlinked..."
    source="$(readlink "${
    
    source}")"
  fi

改成:

 if [ -L "${source}" ]; then
    echo "Symlinked..."
    source="$(readlink -f "${
    
    source}")"
  fi

这个确实管用,但是每次执行完pod install命令后,Pods-app-frameworks.sh的文件内容又恢复原状了。



解决方案

方案一:升级CocoaPods版本

个人比较推荐的方法,但是可能暂时还无法使用。问题将在1.12.1版本修复,如果你遇到这个问题时,CocoaPods版本已经发布到1.12.1或更高版本,推荐通过升级到最新版本解决该问题。

方案二:修改Podfile文件

加上这段代码:

post_install do |installer|
  installer.pods_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

重新执行pod install命令解决问题。

方案三:修改embed_frameworks_script.rb文件

文件位于CocoaPods包下的lib/cocoapods/generator/embed_frameworks_script.rb路径,将文件中的source="$(readlink "${source}")"替换为source="$(readlink -f "${source}")",重新执行pod install命令解决问题。

猜你喜欢

转载自blog.csdn.net/biyuhuaping/article/details/130195913