Xcode 14.3 cocoapod 1.12.0 打包報(bào)錯(cuò)解決

前言

前幾天升級(jí)Xcode到14.3版本,運(yùn)行項(xiàng)目報(bào)錯(cuò),于是記錄下來(lái)。

開發(fā)環(huán)境

macOS: 13.3.1
Xcode: 14.3
CocoaPods: 1.12.0

問(wèn)題描述

[Xcode菜單欄] -> [Product] -> [Archive],進(jìn)行打包操作。執(zhí)行到 Run custom shell script '[CP] Embed Pods Frameworks' 時(shí)報(bào)錯(cuò),報(bào)錯(cuò)相關(guān)日志如下:

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

如圖:


報(bào)錯(cuò)截圖.jpeg

在網(wǎng)上搜索找到一種解決辦法:說(shuō)這是一個(gè) cocoapods 問(wèn)題:https://developer.apple.com/forums/thread/727525https://github.com/CocoaPods/CocoaPods/pull/11828#issuecomment-1497329930
需要修改的是,進(jìn)入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

這個(gè)確實(shí)管用,但是每次執(zhí)行完pod install命令后,Pods-app-frameworks.sh的文件內(nèi)容又恢復(fù)原狀了。



解決方案

方案一:升級(jí)CocoaPods版本

個(gè)人比較推薦的方法,但是可能暫時(shí)還無(wú)法使用。問(wèn)題將在1.12.1版本修復(fù),如果你遇到這個(gè)問(wèn)題時(shí),CocoaPods版本已經(jīng)發(fā)布到1.12.1或更高版本,推薦通過(guò)升級(jí)到最新版本解決該問(wèn)題。

方案二:修改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

重新執(zhí)行pod install命令解決問(wèn)題。

方案三:修改embed_frameworks_script.rb文件

文件位于CocoaPods包下的lib/cocoapods/generator/embed_frameworks_script.rb路徑,將文件中的source="$(readlink "${source}")"替換為source="$(readlink -f "${source}")",重新執(zhí)行pod install命令解決問(wèn)題。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容