Flutter热更新与热加载

Flutter曾支持热更新,允许不重新部署应用即可推送代码更新。但因性能、安全及托管服务器等问题,于2019年放弃该功能。决策考虑了平台政策、安全风险及外部服务依赖。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

之前偶然从Flutter官方文档上看到了支持热更新,当然这是从2019年才开始的

Dynamic updates
The Dart Platform, on which Flutter is built, provides unique abilities for us to push code to your applications without redeploying the app.
Dynamic patching on Android, allowing for code updates to deployed to Flutter applications running on Android directly from a servers.
Dynamic extension loading to allow lazy loading of occasionally used parts of your application

这里的Dynamic patching on Android指的是热更新,Dynamic extension loading指的是热加载,emmm,开始学起来。

2019年6月13日 修改:
今天有位博友告诉我,flutter停止对热更新的支持了,我去看了一下确实如此,请参考上面的Flutter官方链接

Changes
Dropped support for Dynamic updates in 2019. See this bug for details.

原因的话是考虑安全性和需要提供托管服务器影响其他功能开发,参照下面的声明

This was previously on our roadmap for 2019. After investigating this in greater detail, we have decided not to proceed with this work for now.

There were several factors that led us to this decision:

To comply with our understanding of store policies on Android and iOS, any solution would be limited to JIT code on Android and interpreted code on iOS. We are not confident that the performance characteristics of such a solution on iOS would reach the quality that we demand of our product. (In other words, “it would be too slow”.)

There are some serious security concerns. Since these patches would essentially allow arbitrary code execution, they would be extremely attractive malware vectors. We could mitigate this by requiring that patches be signed using the same key as the original package, but this is error prone and any mistake would have serious consequences. This is, fundamentally, the same problem that has plagued platforms that allow execution of code from third-party sources. This problem could be mitigated by integrating with a platform update mechanism, but this defeats the purpose of an out-of-band patching mechanism.

There is currently no out-of-the-box open source hosting solution for patching applications, so we would either have to rely on people configuring their Web servers accordingly, or we would have to create integrations for proprietary third-party services, or we would have to create our own bespoke solution. Hosting patches is a space we are not eager to enter. Having people configure their own server leaves them open to making mistakes with potentially serious implications as explained in the previous point about security. Depending on third-party services puts Flutter in an awkward position of having to pick winners and exposes us to the risk of those projects themselves making policy changes that would affect this feature.

We prefer to spend our engineering effort on other issues for now. We expect to keep experimenting in this space and will probably become serious about this again in the future (for example, we will probably need an update solution for desktop applications), but probably not this year.

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值