如何使用外部库和混淆,如何减少下载尺寸的Flutter应用程序?
我已经构建了一个带有颤音的应用程序,现在可以用于iOS和Android平台。但是,我注意到,App Store下载尺寸似乎很大。例如,对于iOS,我的应用程序的IPA大小为102MB,下载尺寸为85MB。与我创建Android AppBundle相比,这通常是大约30MB。有人可以向我解释为什么iOS和Android应用之间有如此大的区别吗?这只是扑动构建iOS应用程序的方式吗?我该怎么办来解决这个问题?
我还一直在考虑减少应用程序下载尺寸的其他方法。到目前为止,我已经优化了所有图像文件以用于大小,并删除了不必要的飞镖文件。我发生的一件事是我对外部库的使用可以成为问题的一部分吗?例如,我使用Flutter Platform Widgets软件包来帮助提供本地感觉。当我使用它时,我会导入整个文件,就像这样:
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
当然,每当我将其导入任何给定的DART文件时,都可以访问20-30个左右的平台小部件。我使用的小部件是否会导入文件对文件大小有所不同吗?例如,在我所使用的页面上,只需
import 'package:flutter_platform_widgets/src/platform_text_button.dart';
导入必要的小部件,还是根本不会有所作为?
我遇到的另一件事是混淆代码。例如,当我构建iOS版本时,我会运行:
flutter build ios --obfuscate --split-debug-info=debug-info
我在这个论坛上遇到了答案,而其他人说他们已经使用了它,并且已经打破了他们的应用程序,给最终用户带来了糟糕的体验。混淆可能会为最终用户打破应用程序,如果是这样,我该怎么做才能纠正这一问题?它实际上会降低应用程序的下载尺寸吗?
感谢您的帮助!我对任何其他建议也开放,以减少我的应用程序的下载尺寸。
I have built an app with Flutter that is now available for both the iOS and Android platforms. I am noticing, however, that the app store download sizes seem very large. For example, for iOS, my app's ipa size is 102MB and the download size is 85MB. This is in comparison to when I create the Android appbundle, which usually comes in at around 30MB. Can someone explain to me why there is such a big difference between the iOS and Android apps? Is it just the way Flutter builds iOS apps? What can I do to remedy this?
I have also been thinking about other ways I could reduce the download size of my app. So far, I have optimised all image files for size and removed unnecessary dart files. One thing that has occurred to me is could my use of external libraries be part of the problem? For example, I use the Flutter Platform Widgets package to help provide native feel. When I use it, I import the whole file, like so:
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
Of course, that provides access to 20 - 30 or so different platform widgets each time I import it in any given dart file. Would importing the files for only the widgets that I use make a difference to the file size? For example, on a page where all I use is the platform text button, would importing only
import 'package:flutter_platform_widgets/src/platform_text_button.dart';
reduce help to reduce the file size of the app, by only importing necessary widgets, or would it not make a difference at all?
The other thing I have come across is obfuscating the code. For example, when I build the iOS version, I would run:
flutter build ios --obfuscate --split-debug-info=debug-info
I have come across answers on this forum and others where people have said they've used it and it has broken their app, giving a bad experience to the end user. Would obfuscation likely break the app for the end user and if so, what could I do to correct this? Would it actually reduce the app's download size?
Thanks for all your help! I am open to any other suggestions to reduce my app's download size as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您仅导入实际使用的文件的想法可能是不必要的,因为飞镖编译器会自动摄取树木蛋糕,从而删除未使用的代码。
在混淆性方面,我总是使用它,它从来没有给我带来任何问题。
这是我使用的命令:
与仅干净且普通的构建相比,我的命令将输出从44.3MB缩小到12.9MB。现在,这部分是因为现在有3个APK,但是在大多数情况下,仅需要“ app-armeabi-v7a-release.apk”。
我以前从未为iOS构建,所以我对此评论不多。
据说在线指南会更多地缩小包装,但是当我尝试一些方案时,我花了几个小时以0.2MB的收益。我认为这是不值得的。
Your idea of only importing the files you actually use is probably unnecessary, as the Dart compiler automatically tree-shakes, removing unused code.
In terms of obfuscation, I always use it and it has never caused any problems for me.
This is the command(s) I use:
In comparison to just a clean and normal build, my command has shrunk the output from 44.3MB to 12.9MB. Now, that is partially because there are now 3 apks, but most of the time only 'app-armeabi-v7a-release.apk' is needed.
I've never built for iOS before, so I can't comment much about that.
There are guides online that supposedly shrink the package more, but when I tried some of them, I spent several hours for 0.2MB gain. It's not worth it in my opinion.