问题描述
我在使用 java 开发 android 应用程序方面有很好的经验.最近我开始了解flutter.因此,我尝试基于官方 tutorial 创建一个带有 flutter 的简单 android 应用程序.但令人惊讶的是,调试应用程序大小为 25MB,发布 apk 成本超过 7MB.与原生开发的 android 应用程序相比,它确实更大.
I have good experience in android app development using java. Recently I came to know about flutter. So, I have tried to create a simple android app with flutter based on official tutorial. But surprisingly the debug app size is 25MB and release apk costs more than 7MB. It is really larger when compare with native developed android app.
有什么优化的方法吗?
推荐答案
Flutter 团队在 这里.
Flutter team acknowledges it here.
对此有一个解释这里,引用了一样 -
There's an explanation for this here, quoting the same -
在 2018 年 8 月,我们测量了一个最小 Flutter 应用程序的大小(没有Material Components,只是一个 Center 小部件,使用 flutter 构建build apk),捆绑并压缩为发行版 APK,大约 4.7MB.
对于这个简单的应用程序,核心引擎大约为 3.2MB(压缩后),框架+app代码约840KB(压缩),LICENSE文件55KB(压缩),必备Java代码(classes.dex)为57KB(压缩后),大约有533KB(压缩)ICU 数据.
For this simple app, the core engine is approximately 3.2MB (compressed), the framework + app code is approximately 840KB (compressed), the LICENSE file is 55KB (compressed), necessary Java code (classes.dex) is 57KB (compressed), and there is approximately 533KB of (compressed) ICU data.
当然,YMMV,我们建议您通过以下方式衡量自己的应用运行 flutter build apk 并查看build/app/outputs/apk/release/app-release.apk.
Of course, YMMV, and we recommend that you measure your own app, by running flutter build apk and looking at build/app/outputs/apk/release/app-release.apk.
此外,对于较大的应用程序,apk 大小的相对差异可能会更小.Flutter 的开销大小是固定的.
Also, the relative differences in apk size would likely be smaller with larger apps. Flutter's overhead size is fixed.
这篇关于Flutter 应用体积过大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!