美文网首页
Flutter iOS ipa文件过大问题

Flutter iOS ipa文件过大问题

作者: BeRicher | 来源:发表于2020-10-08 14:31 被阅读0次

    写完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.
    

    相关文章

      网友评论

          本文标题:Flutter iOS ipa文件过大问题

          本文链接:https://www.haomeiwen.com/subject/jixhpktx.html