Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

17云:安装包瘦身 #17

Open
platojobs opened this issue Aug 7, 2021 · 0 comments
Open

17云:安装包瘦身 #17

platojobs opened this issue Aug 7, 2021 · 0 comments
Labels
Technology technology

Comments

@platojobs
Copy link
Owner

1.常规瘦身方案

1.压缩资源

项目中资源包括图片、字符串、音视频等资源。由于项目中图片比较多,所以资源压缩一般会从图片入手。在把图片加入到项目中时候需要采用tinypng或者ImageOptim对图片进行压缩;另外,可以通知设计,对切图进行压缩处理再上传;不需要内嵌到项目中的图片可以改为动态下载。

  • png,jpg,gif可以替换成webp
  • 动画图片可替换为lotties、APNG
  • 小图或表情图可替换为iconFont
  • 大图可替换为svg
2.删除无用/重复资源

删除无用的资源。项目中主要以删除图片为主:

  • 图片用2x和3x图就可以,不要用1x图。
  • 可以用LSUnusedResources搜索出未使用的图片然后删除之。
    注意:该软件搜索出来的图片有可能项目中还在用,删除之前需要在工程中先搜索下图片是否有使用再确认是否可以删除。
3.删除无用代码

删除无用类和库:可以用WBBladesForMac来分析,注意:通过字符串调用的类也会检测为无用类。

2.非常规瘦身方案

1.Strip :去除不必要的符号信息。

-Strip Linked Product Strip Swift Symbols 设置为 YESDeployment Postprocessing 设置为 NO,发布代码的时候也需要勾选 Strip Swift Symbols

Strip Debug Symbols During CopySymbols Hidden by Defaultrelease下设为YES
Dead Code Stripping 设置为 YES
对于动态库,可用strip -x [动态库路径] 去除不必要的符号信息

2.Make Strings Read-Only设为YES。

3.Link-Time Optimization(LTO)release下设为 Incremental。WWDC2016介绍编译时会移除没有被调用的方法和代码,优化程序运行效率。

4.开启BitCode

  • watchOS,Bitcode是必选的;
  • Mac OS是不支持Bitcode的。
  • 对于iOS,Bitcode是可选的,根据你对APP的要求已经第三方库的事情情况决定是否使用

5.去除异常支持。不能使用@Try @catch,包只缩小0.1M,效果不显著。

Enable C++ ExceptionsEnable Objective-C Exceptions设为NO,Other C Flags添加-fno-exceptions

6.不生成debug symbols:不能生成dSYM,效果非常显著。

Generate debug symbols选项 release 设置为NO

@platojobs platojobs added the Technology technology label Aug 7, 2021
@platojobs platojobs added this to technology in PJ文摘 Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Technology technology
Projects
No open projects
PJ技术类
Awaiting triage
PJ文摘
technology
Development

No branches or pull requests

1 participant