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 on a remote device #10

Open
bazsisz opened this issue Jun 11, 2024 · 4 comments
Open

Hot reload on a remote device #10

bazsisz opened this issue Jun 11, 2024 · 4 comments

Comments

@bazsisz
Copy link

bazsisz commented Jun 11, 2024

As avalonia is a multi-platform framework, it would be nice if hot reload would work also on other platforms than Windows. Unfortunately it seems to not work on Android (unless i am missing something). When trying to deploy my application to an android device using USB debugging, the method EnableHotReload throws an exception as the appFilepath parameter not exists. The path points to the App.axaml.cs file on my computer. My first guess that the system tries to find this path on the Android device.

Is this is a known issue or simply i missed something crucial? I tried to do everything as the README.txt stated.

Thanks in advance!

@Kir-Antipov
Copy link
Owner

As avalonia is a multi-platform framework, it would be nice if hot reload would work also on other platforms than Windows.

HotAvalonia is a cross-platform library. I don't even use Windows myself, so of course I made sure that it works on other operating systems like Linux and macOS :)

The path points to the App.axaml.cs file on my computer. My first guess that the system tries to find this path on the Android device.

It sure does. HotAvalonia is tooling-independent thanks to the fact that it works directly with your files. This means you can edit them from any text editor of your choice, and hot-reload is gonna work no matter what. However, it also presents some challenges in cases like yours. Citing the README:

Mobile Development: Unlike in a local development environment, where your application and project files share the same filesystem, in an emulator, your application is running on what effectively is a remote system. To enable hot reloading there, your project must be accessible by the emulator. This can be achieved by mounting the directory you are working with as a remote filesystem on the emulated device. With this setup, hot reload on emulators should work, but there may be additional challenges yet to be discovered. Feel free to open an issue if you've stumbled upon any!

Additionally, if the mount point differs from the location of the source project on your PC (which, judging by the fact that you mention Windows, it will, because Windows uses some crazy pathing system), you can provide it manually to the .EnableHotReload() method like so:

this.EnableHotReload("/path/to/my/project/on/android/App.axaml");

@Kir-Antipov
Copy link
Owner

Since you are trying to debug the app on a real device rather than via an emulator, mounting may be a bit challenging because it requires root access, which you might not have. In this scenario, I suggest switching gears and moving to an emulator, as a good one will streamline this process for you.

@Kir-Antipov Kir-Antipov changed the title Android Issue Hot reload on a remote device Jun 11, 2024
@bazsisz
Copy link
Author

bazsisz commented Jun 11, 2024

Thanks for your response!

Unfortunately emulators dont work for us. If I understand right, the remote device should have access to the source files on the host computer to be able to watch for changes to make hot reload active, right? Right now, it seems complicated to me. I will try to figure out something.

Maybe some kind of drive sync application, where the application keeps folders and files syncronized?
I will share my solution, if I can come up with any :D

Thanks again. Keep up the good work! :D

@Kir-Antipov
Copy link
Owner

If I understand right, the remote device should have access to the source files on the host computer to be able to watch for changes to make hot reload active, right?

Absolutely!

Maybe some kind of drive sync application, where the application keeps folders and files syncronized?

That's why I suggested mounting a network drive, as that's the whole point of their existence. However, mounting a drive on an unrooted Android device is not possible, as far as I know, unless your version of the OS explicitly provides such functionality in the user space (e.g., somewhere in the settings). Therefore, I'm afraid using HotAvalonia is not feasible in your scenario unless you do find a third-party app capable of syncing source files on your PC with their copies on your Android device.

What I can do is abstract away calls to the filesystem, allowing me to supply HotAvalonia with different virtual filesystem implementations depending on the context. One of these implementations could establish a connection from your device to a satellite HotAvalonia-branded app running on your PC. For example:

this.EnableHotReload(IPEndPoint.Parse("192.168.0.42:1984"));

Instead of accessing a local filesystem, the app would make calls over a local network to your PC.

This is just a concept, but it should allow HotAvalonia to work in virtually any scenario imaginable. However, it will require a tremendous amount of work. Additionally, with files being sent over the network, there is now a security aspect that needs to be properly handled on my side, and oh boy do I love dealing with security issues. So, yeah, this is definitely not something that's going to be implemented by tomorrow morning :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants