1,使用QC編輯器生成.app文件:
點擊構建項目,會生成這個qt_test文件(尾綴為.app,一般是不顯示尾綴,是看不到的)
2,使用macdeployqt這個程序把依賴包打入.app中:
命令行命令:
前邊是macdeployqt程序,后邊是QC生成的幾百K的.app文件。
zdeMacBook-Pro:~ z$ /Users/z/Qt5.14.1/5.14.1/clang_64/bin/macdeployqt /Users/z/qt/build-qt_test-Desktop_Qt_5_14_1_clang_64bit-Release/qt_test.app
然后你會發現之前的.app文件變成了好幾十M大小的文件,如下圖:
這個截圖說明,這個.app文件就是直接可以在本機雙擊打開了。接下來要更改這個應用的名字,鼠標右擊這個好幾十M的.app名字,選擇顯示包內容,打開Contents文件夾下面的info.plist文件(如果本機安裝了Xcode,那可以直接打開,如果沒安裝則使用文本編輯器打開就行):
最后這個文件是這個樣子的:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleExecutable</key> <string>硬件連接器</string> <key>CFBundleIconFile</key> <string>ironman.icns</string> <key>CFBundleIdentifier</key> <string>123123com.mk.qt-test</string> <key>CFBundlePackageType</key> <string>APPL</string> <key>CFBundleSignature</key> <string>????</string> <key>LSMinimumSystemVersion</key> <string>10.13</string> <key>NOTE</key> <string>This file was generated by Qt/QMake.</string> <key>NSPrincipalClass</key> <string>NSApplication</string> <key>NSSupportsAutomaticGraphicsSwitching</key> <true/> <key>CFBundleDisplayName</key> <string>硬件連接器</string> <key>CFBundleName</key> <string>硬件連接器</string> </dict> </plist>
3,應用中增加圖標:
在生成完畢的幾十M的.app文件中-->顯示包內容-->把圖標拷貝到Resources文件夾中,並在info.plist文件中修改條目參數:
<string>ironman.icns</string>
刷新文件夾,或者稍等一輛分鍾,會發現應用的圖標從默認變為設置的圖標:
4,簽名.app文件:
登錄開發者平台 https://developer.apple.com/
按照操作步驟得到兩個密鑰:
上面兩個密鑰用鑰匙串工具打開,能夠看見名稱:
雙引號中放入密鑰的名稱,運行簽名命令。
codesign --deep --force --verbose --sign "<identity>" Application.app
檢查密鑰命令:
codesign -dvvv qt_test.app
打包.pkg文件:
productbuild --component qt_test.app /Applications/ --sign "Developer ID Installer: 公司英文名. (H94V*****)" --product qt_test.app/Contents/Info.plist qt_test.pkg
上面的命令行解釋:
productbuild 生成pkg文件的命令
--component 后面根着要打包的.app(已經簽名)的路徑
/Applications/ 表示安裝目錄
--sign 表示使用 Developer ID Installer這個簽名文件進行簽名
--product 后面根哪個.plist文件
qt_test.pkg 這個是生成的pkg文件的輸出路徑
生成完的pkg文件使用命令行安裝一下,這樣能看到安裝過程中發生了什么,尤其是安裝位置:
sudo installer -store -pkg qt_test.pkg -target /
簽名資料參考:
https://blog.csdn.net/u014599371/article/details/103472038
https://blog.csdn.net/casun_li/article/details/71741968
生成的.pkg文件結束 😄😄