Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot reload support? #14

Closed
szotp opened this issue Mar 1, 2018 · 13 comments
Closed

Hot reload support? #14

szotp opened this issue Mar 1, 2018 · 13 comments

Comments

@szotp
Copy link

szotp commented Mar 1, 2018

Hi, I'm interested in adding support for hot reload and debugging, but I don't know enough about flutter/dart ecosystem. Would implementing flutter/flutter#5043 solve the problem or is it more complicated?

Something like flutter connect http://127.0.0.1:49278/ to completely bypass device detection, etc.

@szotp
Copy link
Author

szotp commented Mar 5, 2018

Did some research on this. Not sure if it will be useful to anyone

  • I added fake device and hardcoded executable path and Uri on both sides. flutter run would then launch the .app and correctly perform the 'r' reload. 'R' reload did not work.

  • full reload did not work because it is not handled in the embedder: https://github.com/flutter/engine/blob/master/shell/platform/embedder/platform_view_embedder.cc#L53. I could make it work by copying some code from the ios platform view. This made flutter run + R work.

  • VSCode extension uses daemon, which somehow performs hot reload and restart differently than the run command. Nor debugging nor reloading would work. Something about invalid UTF8 would appear when trying to reload.

@stuartmorgan
Copy link
Collaborator

I haven't looked at reload support yet, so I don't have any extra insight into what all is necessary. I think we'll need to discuss with Flutter developers how reloading should work in the embedding model though (e.g., it might make sense for it to be exposed as an embedding API). At a high level, I don't think we want people to have to launch applications with flutter run to get tooling support.

@szotp
Copy link
Author

szotp commented Mar 6, 2018

Thanks for the answer. I got it to work somehow. Perhaps by switching to flutter's master branch. For anyone interested these are the steps required:

  1. Create hardcoded desktop device. I used port 5300.
    szotp/flutter@5c06b5d
  2. Supply these arguments in the client:
    [CommandLine.arguments[0], "--observatory-port=50300", "--start-paused"]
  3. Launch the app from Xcode.
  4. Open the project_example in Visual Studio Code. Make sure it works on iOS (plist needed).
  5. Press F5. Debugging and hot reload should work. Restart reload requires some changes in the engine.

I think I could improve the fork and prepare it for merge:

  1. Add flag in the config to enable the desktop device so only people interested in it can see it.
  2. Execute some script in the flutter, perhaps $(PROJECT_DIR)/launch.{sh/bat} that will compile and launch the app, so we don't have to do it manually via Xcode. Script would also return an Uri to connect.

@putraxor
Copy link

hi @szotp I got this error while using that hacks

NoSuchMethodError: Class 'AppDomain' has no instance method 'startApp' with matching arguments.
Receiver: Instance of 'AppDomain'
Tried calling: startApp(Instance of 'DesktopDevice', "/Users/wizard/Desktop/DEV/flutter-desktop-embedding/example_flutter", "lib/main.dart", null, Instance of 'DebuggingOptions', true, applicationBinary: null, dillOutputPath: null, ipv6: false, packagesFilePath: null, projectRootPath: null, trackWidgetCreation: false)
Found: startApp(Device, String, String, String, DebuggingOptions, bool, {String applicationBinary, bool trackWidgetCreation, String projectRootPath, String packagesFilePath, bool ipv6}) => Future<AppInstance>
Exited (1)

@stuartmorgan
Copy link
Collaborator

Now that attach mode has been added to Dart Code, adding hot reload should be doable without any hackery since it's exposed via the observatory's reloadSources command. Assuming that works as well as the daemon reloads (I haven't tested yet) it would just be a case of adding a Dart Code command to invoke it.

@xxgreg
Copy link

xxgreg commented Jun 2, 2018

With IntelliJ I was able to attach the debugger using the "Dart Remote Debug" run configuration. However it looks like hot reload isn't supported yet when attaching in this way.

There is an open issue to implement this. See: flutter/flutter-intellij#2250

@stuartmorgan
Copy link
Collaborator

stuartmorgan commented Jun 2, 2018

Based on recent discussion in a Dart Code issue, hot reload via the observatory relies on a hook that's registered by flutter-tools, so just attaching to a desktop process won't allow hot reload after all.

It looks like we'll probably need either some kind of hook in the Flutter tools, or a desktop runner that provides the same functionality.

@putraxor
Copy link

Is there a good news?

@stuartmorgan
Copy link
Collaborator

No, see my last comment.

stuartmorgan added a commit to stuartmorgan/flutter-desktop-embedding that referenced this issue Dec 6, 2018
Provides basic instructions for debugging the Flutter side of a desktop
application, since the normal approaches for Flutter debugging require
some modifications on desktop.

Related to issue google#14 and issue google#164, although doesn't fully address
either.
@daniel-v
Copy link

daniel-v commented Dec 7, 2018

I consider this a strong selling point for developers. Hot reload is frigging awesome!

franciscojma86 pushed a commit that referenced this issue Dec 10, 2018
Provides basic instructions for debugging the Flutter side of a desktop
application, since the normal approaches for Flutter debugging require
some modifications on desktop.

Related to issue #14 and issue #164, although doesn't fully address
either.
@stuartmorgan stuartmorgan added this to To do in Overview Kanban Dec 12, 2018
@1l0
Copy link

1l0 commented Feb 17, 2019

I think this issue can be closed because hot reload have been implemented in flutter attach already.

@stuartmorgan
Copy link
Collaborator

The reason it's still open is that the current instructions still use the device-id hack rather than something supported. Most of the necessary work to move away from that is done now, but there's a bit more needed before the VS Code workflow that's currently documented can switch.

@stuartmorgan
Copy link
Collaborator

Moved to flutter/flutter#30707 (solving the devices issues for run would address the attach case as well, so that issue covers both).

(Debugging.md will continue to be updated as the need for special handling changes.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

6 participants