通過實踐,已經調研過并實施的有效方案:
1. 刪除無用的資源庫
結果:刪除無用私有庫代碼,刪除無用的庫,有效果
2. 無用圖片源刪除(手動篩查,較耗時,效果微弱)
過程: LSUnusedResources 查找無用圖片,注意:
[UIImage imageNamed:[NSString stringWithFormat:"icon_%d.png",index]]
這種使用圖片的方式,可能會被誤刪
結果:使用效果不佳,基本無幫助,選擇手動篩查
3. 項目圖片壓縮
結果:使用壓縮圖片網址,有效果
4. 清理項目中的plist文件
結果:有效果 不明顯
5. 無用三方庫調研,
結果:選擇性刪除,調研后目前沒有可刪除的
6. 無效文件刪除
結果:無效類文件刪除,無效方法刪除,缺少方法檢索工具,手動檢索很耗時,效果微弱
7. 無用import去除(linkMap分析結果)
過程:使用 LinkMap 分析庫的使用情況,效果微弱,可忽略不計
* 59.27M YXCommonBusiness
* 23.27M YXExam
* 12.15M YXCareer
* 10.90M AgoraRtcEngineKit
* 9.89M YXPractice
* 9.43M YXKnowledgeBase
* 8.08M YXPoints
* 7.64M YXCourse
* 5.04M YXFuDaoSDK
* 4.35M YXFudaoBase
* 1.51M AgoraRtmKit
* 1.07M libcrypto.a
* 1.00M libjcore-ios-2.3.4.a
8.相關配置排查 效果不明顯
過程:
1.配置編譯選項 Generate Debug Symbols 設置為NO
結果:不可用,影響bugly
2.舍棄架構armv7
結果:不影響安裝包大小,build setting 里 DEAD_CODE_STRIPPING = YES(默認已經設置YES)
3.編譯器優化級別 Build Settings->Optimization Level有幾個編譯優化選項,release版應該選擇Fastest, Smalllest[-Os] (默認已經設置)
4.去除符號信息 Strip Debug Symbols During Copy 和 Symbols Hidden by Default 在release版本應該設為yes,可以去除不必要的調試符號 (今天配置設置,看效果)
5.Strip Linked Product:DEBUG下設為NO,RELEASE下設為YES(默認設置)
9. strip - 相關配置項
過程:經過調研,有兩種去除動態庫多余符號(符號表等)的方式:
1.在鏈接時去除,即在動態庫工程中Other Linker Flags中添加-s參數,經過測試:不管是在啟動時加載,還是手動方式加載動態庫都沒問題。于是準備使用這個方案。然而,在執行的時候發現了一個嚴重的問題:加了此參數后,不能生成完整的dsym文件,這會影響崩潰后符號的解析。此方案作罷。
2.使用strip -x命令處理動態庫。因為是對動態庫產物進行處理,所以不會對dsym產生影響,經過測試,strip后的動態庫,也可以使用dsym文件找到符號。于是我們嘗試在工程中添加腳本統一處理工程中的動態庫。在添加腳本的時候遇到個問題:動態庫被拷貝到沙盒的時候會簽名,而我們的strip操作發生在這個后面。在debug環境下,加載動態庫的時候會提示簽名后動態庫被修改的錯誤。而在release導出包的時候會重新對動態庫進行簽名。所以在release下不會有問題。最終,我們修改了腳本,只在release環境下,執行strip操作:
經過strip處理后共計 減少21M瘦身 效果明顯
具體代碼如下 :
if [ $CONFIGURATION == Release ]; then
strip -x ${BUILT_PRODUCTS_DIR}/YYText/YYText.framework/YYText
strip -x ${PODS_ROOT}/YXCharts/Carthage/Build/iOS/Charts.framework/Charts
strip -x ${PODS_ROOT}/QNRTCKit/Pod/iphoneos/QNRTCKit.framework/QNRTCKit
strip -x ${BUILT_PRODUCTS_DIR}/Masonry/Masonry.framework/Masonry
strip -x ${BUILT_PRODUCTS_DIR}/TZImagePickerController/TZImagePickerController.framework/TZImagePickerController
strip -x ${BUILT_PRODUCTS_DIR}/SVGKit/SVGKit.framework/SVGKit
strip -x ${BUILT_PRODUCTS_DIR}/ZYBannerView/ZYBannerView.framework/ZYBannerView
strip -x ${BUILT_PRODUCTS_DIR}/YYModel/YYModel.framework/YYModel
strip -x ${BUILT_PRODUCTS_DIR}/YYImage/YYImage.framework/YYImage
strip -x ${BUILT_PRODUCTS_DIR}/YYCategories/YYCategories.framework/YYCategories
strip -x ${BUILT_PRODUCTS_DIR}/YYCache/YYCache.framework/YYCache
strip -x ${BUILT_PRODUCTS_DIR}/WZLBadge/WZLBadge.framework/WZLBadge
strip -x ${BUILT_PRODUCTS_DIR}/WebViewJavascriptBridge/WebViewJavascriptBridge.framework/WebViewJavascriptBridge
strip -x ${BUILT_PRODUCTS_DIR}/UITableView+FDTemplateLayoutCell/UITableView+FDTemplateLayoutCell.framework/UITableView+FDTemplateLayoutCell
strip -x ${BUILT_PRODUCTS_DIR}/TYCyclePagerView/TYCyclePagerView.framework/TYCyclePagerView
strip -x ${BUILT_PRODUCTS_DIR}/TTTAttributedLabel/TTTAttributedLabel.framework/TTTAttributedLabel
strip -x ${BUILT_PRODUCTS_DIR}/SwipeView/SwipeView.framework/SwipeView
strip -x ${BUILT_PRODUCTS_DIR}/SSZipArchive/SSZipArchive.framework/SSZipArchive
strip -x ${BUILT_PRODUCTS_DIR}/SDWebImage/SDWebImage.framework/SDWebImage
strip -x ${BUILT_PRODUCTS_DIR}/SDCycleScrollView/SDCycleScrollView.framework/SDCycleScrollView
strip -x ${BUILT_PRODUCTS_DIR}/ReactiveCocoa/ReactiveCocoa.framework/ReactiveCocoa
strip -x ${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework/Reachability
strip -x ${BUILT_PRODUCTS_DIR}/Qiniu/Qiniu.framework/Qiniu
strip -x ${BUILT_PRODUCTS_DIR}/Protobuf/Protobuf.framework/Protobuf
strip -x ${BUILT_PRODUCTS_DIR}/MZFormSheetPresentationController/MZFormSheetPresentationController.framework/MZFormSheetPresentationController
strip -x ${BUILT_PRODUCTS_DIR}/MZAppearance/MZAppearance.framework/MZAppearance
strip -x ${BUILT_PRODUCTS_DIR}/MJRefresh/MJRefresh.framework/MJRefresh
strip -x ${BUILT_PRODUCTS_DIR}/MBProgressHUD/MBProgressHUD.framework/MBProgressHUD
strip -x ${BUILT_PRODUCTS_DIR}/LKDBHelper/LKDBHelper.framework/LKDBHelper
strip -x ${BUILT_PRODUCTS_DIR}/IQKeyboardManager/IQKeyboardManager.framework/IQKeyboardManager
strip -x ${BUILT_PRODUCTS_DIR}/HMSegmentedControl/HMSegmentedControl.framework/HMSegmentedControl
strip -x ${BUILT_PRODUCTS_DIR}/HappyDNS/HappyDNS.framework/HappyDNS
strip -x ${BUILT_PRODUCTS_DIR}/GCDWebServer/GCDWebServer.framework/GCDWebServer
strip -x ${BUILT_PRODUCTS_DIR}/FSCalendar/FSCalendar.framework/FSCalendar
strip -x ${BUILT_PRODUCTS_DIR}/FMDB/FMDB.framework/FMDB
strip -x ${BUILT_PRODUCTS_DIR}/FLAnimatedImage/FLAnimatedImage.framework/FLAnimatedImage
strip -x ${BUILT_PRODUCTS_DIR}/FDStackView/FDStackView.framework/FDStackView
strip -x ${BUILT_PRODUCTS_DIR}/FDFullscreenPopGesture/FDFullscreenPopGesture.framework/FDFullscreenPopGesture
strip -x ${BUILT_PRODUCTS_DIR}/DZNEmptyDataSet/DZNEmptyDataSet.framework/DZNEmptyDataSet
strip -x ${BUILT_PRODUCTS_DIR}/CocoaLumberjack/CocoaLumberjack.framework/CocoaLumberjack
strip -x ${BUILT_PRODUCTS_DIR}/CocoaAsyncSocket/CocoaAsyncSocket.framework/CocoaAsyncSocket
strip -x ${BUILT_PRODUCTS_DIR}/AFNetworking/AFNetworking.framework/AFNetworking
strip -x "${PODS_ROOT}/CCLivePlaySDK/SDK/Live_iOS_Play_SDK(有連麥)/CCSDK.framework/CCSDK"
strip -x "${PODS_ROOT}/CCLivePlaySDK/SDK/Live_iOS_Play_SDK(有連麥)/DWDrmServer.framework/DWDrmServer"
strip -x "${PODS_ROOT}/CCLivePlaySDK/SDK/Live_iOS_Play_SDK(有連麥)/IJKMediaFramework.framework/IJKMediaFramework"
strip -x "${PODS_ROOT}/CCLivePlaySDK/SDK/Live_iOS_Play_SDK(有連麥)/WebRTC.framework/WebRTC"
fi
10. 后續計劃做的
- oc與swift混編 ,全部換成oc
- 重量級三方庫引入是否替換成輕量級,或者自己寫
- 無效方法檢索工具
- 合并重復的圖片資源
- 制定資源文件維護規范
- 減少項目中的xib、storyboard的使用
參考鏈接
iOS中.app .dSYM .ipa .xcarchive 文件的區別 以及為什么蘋果商店包與我們產出的ipa大小有差別