microsoft / vscode-dotnettools

This is a feedback repository to capture issues logged for the C# Dev Kit and related extensions from Visual Studio Code
Other
210 stars 7 forks source link

The **XAML Hot Reload** feature does not work when debugging on Android devices. #1241

Closed Calichi closed 6 days ago

Calichi commented 1 month ago

Type: Bug

The changes are not applied after editing and saving a XAML file, even when pressing the "Fire" button. The .NET Hot Reload output displays No changes were found.

Extension version: 1.0.6 VS Code version: Code 1.90.2 (5437499feb04f7a586f677b155b039bc2b3669eb, 2024-06-18T22:34:26.404Z) OS version: Windows_NT x64 10.0.22631 Modes:

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i3-10110U CPU @ 2.10GHz (4 x 2592)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|7.84GB (1.94GB free)| |Process Argv|--crash-reporter-id 19165560-5fd2-482a-994e-35e72cd32781| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368cf:30146710 vspor879:30202332 vspor708:30202333 vspor363:30204092 vstes627:30244334 vscod805:30301674 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyone:30548225 962ge761:30959799 pythongtdpath:30769146 welcomedialogc:30910334 pythonnoceb:30805159 asynctok:30898717 pythonregdiag2:30936856 pythonmypyd1:30879173 2e7ec940:31000449 pythontbext0:30879054 accentitlementst:30995554 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 jchc7451:31067544 chatpanelc:31048052 dsvsc021:30996838 f3je6385:31013174 pythoncenvpt:31062603 a69g1124:31058053 dvdeprecation:31068756 dwnewjupyter:31046869 newcmakeconfigv2:31071590 impr_priority:31082723 ```

| VS Bug 2113764

BretJohnson commented 3 weeks ago

@Calichi - FYI, XAML Hot Reload should work as you type. Saving the file shouldn't be necessary. And the "No changes were found" message actually refers to C# changes, not XAML changes, though we're working on improving that message to make it more explicit. FYI on all that.

As for the core issue here, can you provide more info. If you create a new, simple MAUI project (bring up the command palette / .NET: New Project... / .NET MAUI) does Hot Reload work there? Does it fail for all pages in your app or just some? When it fails, can you please share the contents of the .NET Hot Reload output pane and the Debug Console app output, especially searching for Hot Reload related errors (look for Hot Reload) in the app output.

Thanks. I would like to get this issue tracked down & working, both for you and for others who may run into the same problem, whatever it is.

Calichi commented 3 weeks ago

@BretJohnson - I am attaching a video divided into two parts of the entire process. The overlay of the mobile device screen is not synchronized with the video, but it was recorded during the demonstration.

https://github.com/microsoft/vscode-dotnettools/assets/45352964/2a88cbe2-6891-43d2-aae6-425da68cdb23

https://github.com/microsoft/vscode-dotnettools/assets/45352964/d67c5dc1-54ea-4f1d-ac5c-5bb681e69abb

Calichi commented 3 weeks ago

@BretJohnson - Note also, there is an instruction: ‘Start sdb and execute…’ What is sdb? Could there have been a typo when trying to write adb, or is it some tool that I am unfamiliar with? I have already conducted a search, but I cannot find anything related to it

BretJohnson commented 3 weeks ago

@BretJohnson - Note also, there is an instruction: ‘Start sdb and execute…’ What is sdb? Could there have been a typo when trying to write adb, or is it some tool that I am unfamiliar with? I have already conducted a search, but I cannot find anything related to it

Where do you see that message? Can you paste the full message or a screenshot maybe? And thank you for the videos - they are indeed helpful.

Calichi commented 3 weeks ago

@BretJohnson - The message is located in the yellow-highlighted area, but it is in Spanish. Bug_start_sdb

BretJohnson commented 3 weeks ago

@BretJohnson - The message is located in the yellow-highlighted area, but it is in Spanish. Bug_start_sdb

Ah, gotcha. Below is the English version of that UI. sdb isn't a typo, it refers to Android debugger technology. Though as I read that message it does seem confusing, it kind of reads like an instruction to the user on something they should do rather than an explanation of what the build/launch process is doing automatically to connect the debugger. I'll create a bug on that, suggesting the message improved. Thanks for pointing it out.

image

BretJohnson commented 3 weeks ago

But as for your issue, the Hot Reload initialization error: No HotReload connection specified message in the app launch output indicates a problem. XAML Hot Reload won't work if that message shows up. Now to figure out why - what's going wrong that triggers that.

Can you please try this:

  1. cd "C:\Program Files (x86)\Android\android-sdk\platform-tools" (assuming your android sdk is installed there, which it normally is)
  2. See what the output of .\adb.exe shell ls -l /data/local/tmp is. There should be an ide-launchenv.txt file in that directory, which is how environment variables, like the one used for the HotReload connect info, get passed to the Android app at launch time. If something went wrong creating that file - perhaps a permission issue with the Android device/emulator in question - that would cause the symptoms you see.
BretJohnson commented 3 weeks ago

And what kind of Android device is this? It's a physical Android device, not an emulator, right? Can you try with an emulator image, like say a Pixel 7 emulator, and see if that works. My guess is that there's some security issue (or possibly a non security device specific issue) that causes using adb to create the /data/local/tmp/ide-launch-env.txt file to fail on that device. If that's the case, I'd like us to handle that scenario better, though I'm not sure how yet. In any case, let's see what you find with the above checks & go from there. Thanks for your help tracking this down.

image

Calichi commented 3 weeks ago

@BretJohnson - Indeed, I am using a physical mobile device to debug my applications, and I have no intention of doing so on an emulator. For the same reason, I am seeking assistance. Perhaps you could explain how executing on the emulator could help resolve the issue with the physical device? Or what is their relationship?

It’s worth mentioning that I have debugged on the Windows target, and Hot Reload works perfectly.

Perhaps it’s not relevant, but I usually work with Visual Studio Community, and everything works perfectly there. I wanted to bring my project to VS Code because I heard that it now supports Hot Reload on Android devices, and honestly, it’s more convenient for me to work in VS Code.

Finally, I am fully willing to provide any information you need to help resolve this issue.

Calichi commented 3 weeks ago

@BretJohnson - This is the result of executing the mentioned command, but on the physical device, not on an emulator. As you can see, the mentioned file appears ide-launch-env.txt. However, it differs slightly in the name. Could this be the cause of the issue?

Captura de pantalla 2024-07-02 180438

BretJohnson commented 3 weeks ago

@Calichi - Thanks for that info. Can you also share the results of running this adb command (with the physical device connected): .\adb.exe shell cat /data/local/tmp/ide-launchenv.txt And the file name looks correct for you - it should indeed be ide-launchenv.txt. The issue must be something else.

As for running on an emulator, I only mentioned that to better understand what scenarios do & don't work for you, as a troubleshooting step. But you don't need to do it - the adb output above is the most useful. And indeed my goal, as is yours, is figure out why this isn't working for you, with your device, and fix things so it does (probably by making some change in our code, though maybe there's a workaround in advance of that).

Thanks again for your help tracking this down. We're getting closer.

Calichi commented 3 weeks ago

@BretJohnson

Here's requested execution's result for the given command:


Captura de pantalla 2024-07-02 212011

BretJohnson commented 3 weeks ago

@Calichi Thanks. That looks valid. As the next check do you think you can add a little code to your app to get the value of the RuntimeInformation.OSDescription property, running that on your Android device (like in the debugger) and see what it returns. The current code checks if RuntimeInformation.OSDescription.Contains("android") in order to determine if it's an Android device - if that check returned false for some reason, it would result in the behavior you see. That check may not be exactly right, for all devices, and need to be updated - but we'll see, based on what your device reports. Thanks again.

Calichi commented 3 weeks ago

@BretJohnson

Here's the result.

Captura de pantalla 2024-07-02 215019

Calichi commented 3 weeks ago

@BretJohnson

More information.

Captura de pantalla 2024-07-02 221051

BretJohnson commented 3 weeks ago

Thanks. So that's the issue. And this device is an OPPO A15 (https://www.oppo.com/en/smartphones/series-a/a15/specs/), right? It looks like the OS there is ColorOS 7.2 based on Android 10, so Android with some customizations. In any case, I'll look to update the code for a better check on whether running on Android, avoiding RuntimeInformation.OSDescription. In the meantime, I can't think of any good workarounds, other than say using an emulator temporarily for Hot Reload. But I'll fix it. We publish weekly pre-release channel updates of the extension. Once the bug here is noted as fix, look for an update published to pre-release there that contains the fix. So you shouldn't have to wait too long. Thanks again very much for your help tracking this down.

Calichi commented 3 weeks ago

@BretJohnson

You’re welcome! Thank you for your attention and follow-up. I’ll wait for the update

BretJohnson commented 3 weeks ago

I'll update this issue to mark it fixed, once we have a fix in place & we'll close the issue after the fix is released publicly.

Calichi commented 3 weeks ago

@BretJohnson

Ok.

I can post another bug about debugging MAUI apps on my Android device, but this one occurs in both VS Code and VS Community.

BretJohnson commented 3 weeks ago

@BretJohnson

Ok.

I can post another bug about debugging MAUI apps on my Android device, but this one occurs in both VS Code and VS Community.

Sounds good. For issues that happen in both VS Windows and VS Code, I'd suggest reproducing it in VS Windows, then create a feedback ticket (Help / Send Feedback / Report a Problem). Feedback tickets include logs which sometimes help. And note on the feedback ticket that you also see it on VS Code. Reporting a separate VS Code bug here, in addition to the VS Windows feedback ticket, shouldn't normally be necessary, but on the other hand it couldn't hurt and will raise visibility so feel free to do that if you'd prefer.

Calichi commented 3 weeks ago

Once again, thank you very much!

ziomek64 commented 1 week ago

For me XAML hot reload works in emulator but doesn't in real device too

BretJohnson commented 6 days ago

This is fixed, in C# extension version 2.39 (and later), currently published to the pre-release channel. @Calichi - After updating to the latest prerelease version of the C# extension, if you still see any problems let us know. @ziomek64 - Same for you. Thanks.