我相信一定有一种非常简单的方法来做到这一点,但我就是找不到……
结语
所以显然,由于我确实需要运行调用install_lib_tool
的脚本,我编写了一个非常通用的脚本,将路径中包含/local/
的任何内容更改为嵌入式副本的路径:
#!/bin/sh
app=$BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH
fw_path=$BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH
app_dyl_list=(`ls $fw_path | grep dylib`)
function change_paths {
local bin=$1
echo change_path $bin
dyl_list=(`otool -L $bin | grep local | awk '{print $1}'`)
for dyl in ${dyl_list[*]}; do
libname=$(basename $dyl)
libname=${libname%%.*}
actual_libname=(`ls $fw_path | grep $libname | xargs basename`)
install_name_tool -change $dyl "@executable_path/../Frameworks/$actual_libname" $bin
printf "\t%s edited\n" $actual_libname
done
}
change_paths $app
for dyl_bin in ${app_dyl_list[*]}; do
change_paths $fw_path/$dyl_bin
done
然后,只需要在将dylibs复制后添加一个运行脚本步骤,无需参数即可运行它(环境变量包含所需的一切)。