Flutter iOS ipa文件过大问题

写完App以后,发现iOS打出的xxx.app有400多兆。

在打包时增加分析参数发现Frameworks居然有380多兆。

flutter build ios --analyze-size

进到里面一看是因为Flutter文件导致的。

翻查官方文档发现:

ios的Flutter二进制文件是带有bitcode的,导致体积增大。

原因是:

If we included variants with and without bitcode for iOS, 
that would even further complicate our variety of binary formats that we produce, 
leading to more confusion for beginner developers, and larger release archives. 
We currently have binaries for (static, dynamic, swift 2.2, swift 2.3, swift 3.0, swift 3.0.1, swift 3.0.2), 
all of which could have both variants with/without bitcode.

如果要上架苹果商店,上传时他们会剥离这些代码,体积会掉下来,但是如果我们想要内部测试怎么办。

可以使用xcrun bitcode_strip命令来剥离bitcode代码。

比如我们打出来的包是 Runner.app,右键显示包内容,依次进入【Frameworks】【Flutter.framework】文件夹。

我们对该文件夹下的【Flutter】进行处理。

运行命令移除bitcode代码

xcrun bitcode_strip Flutter -r -o Flutter

关于xcrun bitcode_strip的文档如下:

       -o    output
              specifies the output file as output.

       -r     specifies the bitcode segment is to be removed.

       -m     specifies  the  bitcode segment is to be removed and a marker is
              left.

       -l     specifies   that   only   the   bitcode    segment    and    the
              (__TEXT,__info_plist)  section is to be left in the Mach-O file.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容