混合开发热加载

在做Flutter开发的时候,它带有热重启/重新加载的功能,但混合开发中在Android项目中集成了Flutter项目,Flutter的热重启/重新加载功能好像失效了,重启加载的步骤

  • 打开一个模拟器,或连接一个设备到电脑上;

  • 关闭我们的APP,然后运行flutter attach;

$ cd flutter_hybrid/flutter_module
$ flutter attach
Waiting for a connection from Flutter on Nexus 5X...

如果,你同时有多个模拟器或连接的设备,运行flutter attach会提示你选择一个设备:

ndroid SDK built for x86 • emulator-5554                        • android-x86 • Android 8.1.0 (API 27) (emulator)
iPhone X                  • 3E3FA943-715F-482F-B003-D46F5902C56C • ios         • iOS 12.1 (simulator)

接下来我们需要flutter attach -d来指定一个设备:  -d后面跟的设备ID。

flutter attach -d 'emulator-5554'

运行APP,然后你会看到:

$ flutter attach
More than one device connected; please specify a device with the '-d <deviceId>' flag, or use '-d all' to act on all devices.

Android SDK built for x86 • emulator-5554                        • android-x86 • Android 8.1.0 (API 27) (emulator)
iPhone X                  • 3E3FA943-715F-482F-B003-D46F5902C56C • ios         • iOS 12.1 (simulator)
jphdeMacBook-Pro:flutter_module jph$ flutter attach -d 'emulator-5554'
Waiting for a connection from Flutter on Android SDK built for x86...
Done.
Syncing files to device Android SDK built for x86...             1,744ms

?  To hot reload changes while running, press "r". To hot restart (and rebuild state), press "R".
An Observatory debugger and profiler on Android SDK built for x86 is available at: http://127.0.0.1:60324/
For a more detailed help message, press "h". To detach, press "d"; to quit, press "q".

说明连接成功了,接下来就可以通过上面的提示来进行热加载/热重启了,在终端输入:

  • r : 热加载;

  • R : 热重启;

  • h : 获取帮助;

  • d : 断开连接;

调试Dart代码

混合开发的模式下,高效调试代码的方式:

  • 关闭APP 

  • 点击AndroidStudio的Flutter Attach按钮(需要首先安装Flutter与Dart插件)

  • 启动APP

//img1.sycdn.imooc.com/szimg/5e787d200936835117180366.jpg

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值