废话不多说直接上干货,打包脚本如下:pkg.sh 文件
#!bin/bash
## 首先查看下当前目录下是否有两个文件夹,如果没有手动拷贝过来
if [ ! -d "Language" ]; then
echo "folder Languge not exist, please copy it"
exit 0
fi
if [ ! -d "Config" ]; then
echo "folder Config not exist, please copy it"
exit 0
fi
## YourProjectName auto-package 创建打包 **************************************************
##1、将QTcreator生成的app拷贝到指定目录下,然后进入到app目录里面(在窗口中可以右键显示包内容进入查看内容)
mkdir YourProjectName.app/Contents/MacOS/log
cp -r sourcecode/YourProjectName/YourProjectName.app .
cp -r Language YourProjectName.app/Contents/MacOS
cp -r config YourProjectName.app/Contents/MacOS
cp sourcecode/commonFile/libcommonFile.1.0.0.dylib YourProjectName.app/Contents/MacOS
cp sourcecode/commonFile/libcommonFile.1.dylib YourProjectName.app/Contents/MacOS
cp sourcecode/commonUI/libcommonUI.1.0.0.dylib YourProjectName.app/Contents/MacOS
cp sourcecode/commonUI/libcommonUI.1.dylib YourProjectName.app/Contents/MacOS
cp sourcecode/Config/libConfig.1.0.0.dylib YourProjectName.app/Contents/MacOS
cp sourcecode/Config/libConfig.1.dylib YourProjectName.app/Contents/MacOS
cp sourcecode/KernalData/libKernalData.1.0.0.dylib YourProjectName.app/Contents/MacOS
cp sourcecode/KernalData/libKernalData.1.dylib YourProjectName.app/Contents/MacOS
cp ../../mac_lib/libZegoExpressEngine.dylib YourProjectName.app/Contents/MacOS
cp ../../mac_lib/libZegoScreenCaptureOSX.dylib YourProjectName.app/Contents/MacOS
cp ../../mac_lib/libQt5Quazip.1.0.0.dylib YourProjectName.app/Contents/MacOS
cp ../../mac_lib/libQt5Quazip.1.dylib YourProjectName.app/Contents/MacOS
cp -r ../../mac_lib/ZegoLiveRoomOSX.framework YourProjectName.app/Contents/MacOS
## macdeployqt qt发布 使用QT自带的打包工具进行打包 **********************************************************
echo " macdeployqt "
macdeployqt YourProjectName.app
##打包完成后,app运行找不到对应的依赖库,因为APP默认去/usr/lib中查找对应的依赖库,肯定找不到
##所以要使用install_name_tool进行依赖库的修改
echo -e "\033[33mstart resolve lib not exits error ... \033[0m"
## YourProjectName 依赖库修改 这个工程依赖的库都要修改目录********************************************************
echo " install_name_tool modify YourProjectName libs-path: "
echo " -- 1.libZegoExpressEngine.dylib"
install_name_tool -change "@rpath/libZegoExpressEngine.dylib" "@executable_path/libZegoExpressEngine.dylib" YourProjectName.app/Contents/MacOS/YourProjectName
echo " -- 2.libZegoScreenCaptureOSX.dylib"
install_name_tool -change "@rpath/libZegoScreenCaptureOSX.dylib" "@executable_path/libZegoScreenCaptureOSX.dylib" YourProjectName.app/Contents/MacOS/YourProjectName
echo " -- 3.libConfig.dylib"
install_name_tool -change "libConfig.1.dylib" "@executable_path/libConfig.1.dylib" YourProjectName.app/Contents/MacOS/YourProjectName
echo " -- 4.libcommonFile.dylib"
install_name_tool -change "libcommonFile.1.dylib" "@executable_path/libcommonFile.1.dylib" YourProjectName.app/Contents/MacOS/YourProjectName
echo " -- 5.libcommonUI.dylib"
install_name_tool -change "libcommonUI.1.dylib" "@executable_path/libcommonUI.1.dylib" YourProjectName.app/Contents/MacOS/YourProjectName
echo " -- 6.libKernalData.dylib"
install_name_tool -change "libKernalData.1.dylib" "@executable_path/libKernalData.1.dylib" YourProjectName.app/Contents/MacOS/YourProjectName
echo " -- 7.ZegoLiveRoomOSX.framework"
install_name_tool -change "@rpath/ZegoLiveRoomOSX.framework/ZegoLiveRoomOSX" "@executable_path/ZegoLiveRoomOSX.framework/ZegoLiveRoomOSX" YourProjectName.app/Contents/MacOS/YourProjectName
echo " -- 8 libQt5Quazip.1.dylib"
install_name_tool -change "libQt5Quazip.1.dylib" "@executable_path/libQt5Quazip.1.dylib" YourProjectName.app/Contents/MacOS/YourProjectName
## libConfig 依赖库修改 这个依赖库同样依赖了其他的库,同样要修改依赖库的目录********************************************************
echo " install_name_tool modify libConfig libs-path: "
echo " -- 1.libcommonFile.dylib"
install_name_tool -change "libcommonFile.1.dylib" "@executable_path/libcommonFile.1.dylib" YourProjectName.app/Contents/MacOS/libConfig.1.dylib
## libcommonUI 依赖库修改 ******************************************************
echo " install_name_tool modify libcommonUI libs-path: "
echo " -- 1.libConfig.dylib"
install_name_tool -change "libConfig.1.dylib" "@executable_path/libConfig.1.dylib" YourProjectName.app/Contents/MacOS/libcommonUI.1.dylib
echo " -- 2.libcommonFile.dylib"
install_name_tool -change "libcommonFile.1.dylib" "@executable_path/libcommonFile.1.dylib" YourProjectName.app/Contents/MacOS/libcommonUI.1.dylib
## libKernalData 依赖库修改 ****************************************************
echo " install_name_tool modify libKernalData libs-path: "
echo " -- 1.libZegoExpressEngine.dylib"
install_name_tool -change "@rpath/libZegoExpressEngine.dylib" "@executable_path/libZegoExpressEngine.dylib" YourProjectName.app/Contents/MacOS/libKernalData.1.dylib
echo " -- 2.libcommonFile.dylib"
install_name_tool -change "libcommonFile.1.dylib" "@executable_path/libcommonFile.1.dylib" YourProjectName.app/Contents/MacOS/libKernalData.1.dylib
echo " -- 3.libConfig.dylib"
install_name_tool -change "libConfig.1.dylib" "@executable_path/libConfig.1.dylib" YourProjectName.app/Contents/MacOS/libKernalData.1.dylib
echo -e "\033[42m resolve lib dependency and pack-release Success ! \033[0m"
文件中有详细的解释。其主要步骤是:1、拷贝QTcreator生成的app文件到当前目录
2、进入到app包中,创建一些目录,用来存放依赖库,配置文件、翻译、皮肤等
3、拷贝所有需要的内容到这个app包中对应的目录
4、使用qt自带的工具macdeployqt 进行打包
5、打包完成后,还需要修改APP这个包所依赖的库的路径,因为APP默认去系统库中寻找,如果是自己封装的库就会存在找不到的问题,使用install_name_tool来修改APP包的依赖库路径
6、修改好之后最后会执行成功,有绿色文字打印success就大功告成了