Issue
In Android Studio after ending the debug/run session and/or unplugging my phone from the computer and restarting the app, the locally installed app seems to not have saved the last hot reload's changes.
I noticed this a few times and decided to run an experiment by having a simple page and introducing a couple simple Text
widgets in separate hot reloads (triggered by my pressing Ctrl+S), and indeed after restarting the app (after having unplugged) only the first of the two Text
widgets appeared, indicating that indeed the last hot reload's changes have been lost.
I'm not sure if this is by design or if something in my development environment is not working.
Either way, I am hoping to be able to easily unplug and have the last changes persist so that when I am discussing my latest changes with other developers away from my computer, we can look at the latest changes.
P.S. I am aware that I can just introduce a dummy change at the end of each development session and unplug so that all the actual changes stick around, but I'm wondering if there is another more elegant solution than adding garbage code.
Solution
Hot reload works by uploading your latest changes into a debuggable process. The source code is compiled into kernel files and sent to the mobile device’s Dart VM. But they are loaded in-memory. When you disconnect the debug process and kill your app, after you open again it will load the libraries from the last real compilation which is in your disk.
Applying changes and saving them both in memory and then disk would actually make the whole process a lot less efficient and is currently unavailable, unfortunately.
If you want to run your application without recompiling it, you can:
- Connect your device
- Open the old installed version of your app
- On the IDE you click on the little bug icon with an arrow (See the screenshot) (or pressing shift twice and then typing "Attach Debugger to Android Process")
- Click OK
Please note: this approach won't work properly if you have native code changed, for instance installing a third party library that adds functionality through platform-channels would require you to recompile the application.
Hope this helps. There's also the same thing on VSCode.
See more at: https://docs.flutter.dev/development/tools/hot-reload
Answered By - Anderson Santos
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.