iDev_01

【已解决】Xcode 14.3 Archive rsync报错

2023-04-06

现象

工程使用了 cocoaPods,打包时遇到了如下报错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Symlinked...

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

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

done

sent 29 bytes received 20 bytes 98.00 bytes/sec

total size is 0 speedup is 0.00

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脚本文件 Pods工程中的Target Support Files/Pods-xxx-frameworks.sh

readlink "${source}"

改为

readlink -f "${source}"

排查过程

  1. 升级cocoaPods指最新版,但并没有什么用,可能他们还没来得及更新

  2. rsync命令,可以用来同步文件,和cp、mv类似。检查出参入参了。把多余的可配置项去掉,于是得到了:

1
2
3
rsync \ 
"../../../IntermediateBuildFilesPath/UninstalledProducts/iphoneos/AFNetworking.framework" \
"/Users/xxx/Library/Developer/Xcode/DerivedData/xxx/Build/Intermediates.noindex/ArchiveIntermediates/xxx/InstallationBuildProductsLocation/Applications/xxx.app/Frameworks"

等等!第一个路径参数为什么是个相对路径?

  1. 查cocoaPods脚本,以下为报错代码
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then
    local source="${BUILT_PRODUCTS_DIR}/$1"
    elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then
    local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")"
    elif [ -r "$1" ]; then
    local source="$1"
    fi

    local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"

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

    if [ -d "${source}/${BCSYMBOLMAP_DIR}" ]; then
    # Locate and install any .bcsymbolmaps if present, and remove them from the .framework before the framework is copied
    find "${source}/${BCSYMBOLMAP_DIR}" -name "*.bcsymbolmap"|while read f; do
    echo "Installing $f"
    install_bcsymbolmap "$f" "$destination"
    rm "$f"
    done
    rmdir "${source}/${BCSYMBOLMAP_DIR}"
    fi

    # Use filter instead of exclude so missing patterns don't throw errors.
    echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\""
    rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}"

那现在只需要追踪source的赋值。

source第一次赋值的结果是一个软连接。

接下来肯定会走下面判断中的代码去拿真实文件的路径,进行第二次赋值。

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

真相大白,readlink "${source}" 得到的结果就是一个相对路径。

查一下readlink命令用法,发现它有个-f的可配置参数,拿到的是绝对路径。也就是最后我们用的解决方法。

使用支付宝打赏
使用微信打赏

若你觉得我的文章对你有帮助,欢迎点击上方按钮对我打赏

扫描二维码,分享此文章