Why hot-reload is not working with my custom flutter embedder?

148 Views Asked by At

I wrote a custom flutter embedder for desktop applications (I would like to support Platform Views that are rendered with Vulkan).

The embedder works fine and is able to run and render flutter applications, handle platform messages etc.

However, I am having many issues when debugging the application either via the command line or via Visual Studio Code.

Here is my process:

1. Create a flutter app, point flutter to my locally compiled engine:

flutter create test_app1 --template=app --local-engine=host_debug

2. build the app in JIT mode for windows-x64 platform

cd test_app1/
flutter assemble --local-engine=host_debug -dTargetPlatform=windows-x64 '-dBuildMode=debug' -dTrackWidgetCreation=true --output="jit_bundle" -dTargetFile="lib/main.dart" debug_bundle_windows_assets

Note that I am not sure this is the proper way to build the dart code for my embedder. This topic is not really documented anywhere I could find. However, it works.

This step creates a flutter_assets dir inside jit_bundle folder which I pass to the flutter embedder interface via FlutterProjectArgs::assets_path.

3. In my embedder code, I pass the following extra switches to flutter's embedder interface via FlutterProjectArgs::command_line_argv

...
config.engine_switches.push_back("--observatory-port=50052");
config.engine_switches.push_back("--vm-service-port=50053");
config.engine_switches.push_back("--disable-service-auth-codes"); 
...

This makes the flutter engine listen to a fixed port that I can later specify to the flutter tools.

  1. Now I wish to attach the flutter debugger to the running application in order to edit the code and view changes via the 'hot-reload' mechanism.

In the test_app1 dir:

flutter attach --device-id=Windows --debug-uri http://127.0.0.1:50053/ --local-engine=host_debug --verbose

I than run the application and I can see the flutter tool successfully attaches:

Syncing files to device Windows...                                  6.2s

Flutter run key commands.
r Hot reload. 
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

A Dart VM Service on Windows is available at: http://127.0.0.1:50430/SWnhkAekOm4=/
The Flutter DevTools debugger and profiler on Windows is available at: http://127.0.0.1:9103?uri=http://127.0.0.1:50430/SWnhkAekOm4=/

Trying to do a minor edit to lib/main.dart yields the following error:

[        ] Skipping target: gen_dart_plugin_registrant
[        ] Skipping target: _composite
[        ] complete
[        ] Performing hot reload...
[  +25 ms] Scanned through 615 files in 23ms
[        ] Syncing files to device Windows...
[   +1 ms] Compiling dart to kernel with 1 updated files
[        ] Processing bundle.
[        ] <- recompile package:test_app2/main.dart 41759271-ee5f-43b2-ac82-99deda071ec8
[        ] package:test_app2/main.dart
[        ] <- 41759271-ee5f-43b2-ac82-99deda071ec8
[        ] Bundle processing done.
[  +28 ms] Updating files.
[   +9 ms] DevFS: Sync finished
[        ] Syncing files to device Windows... (completed in 41ms)
[        ] Synced 0.0MB.
[  +11 ms] <- reject
[  +19 ms] Hot reload was rejected:
[        ] Error while starting Kernel isolate task.
           Try performing a hot restart instead.

If I try to hot reload via the DevTools window I get a popup saying:

enter image description here

So why doesn't it work? How Can I investigate it?


Additional notes:

  • If I create a 'normal' windows application with flutter, and debug it via VS code, hot-reload works.
  • Hot reload even with my locally built engine. And even if I replace the the usage of the built-in embedder entirely with my embedder (by editing the auto generated C++ code of a flutter app)
  • Hot reload stops working if I try to work outside of the auto generated flutter template.
0

There are 0 best solutions below