dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.21k stars 1.75k forks source link

MAUI Blazor Hybrid Android Release: 'BlazorWebView' Fails [8.0.0 preview.5.8529] #16792

Open hitchhiker opened 1 year ago

hitchhiker commented 1 year ago

Is there an existing issue for this?

Describe the bug

Blazor Hybrid app on Android [Release] will start-up, but then move no further past the HTML initialization screen that says 'Loading...'

Expected Behavior

Render the webview

Steps To Reproduce

Exceptions (if any)

'Blazor is not defined' (from console inspect)

.NET Version

8.0 Preview 5

Anything else?

_framework/blazor.webview.js is missing / lost during trimming?

mkArtakMSFT commented 1 year ago

Thanks for contacting us.

Are you not experiencing the same issue without switching to the release configuration? Will the app work if you don't do that?

ghost commented 1 year ago

Hi @hitchhiker. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

hitchhiker commented 1 year ago

Thanks for contacting us.

Are you not experiencing the same issue without switching to the release configuration? Will the app work if you don't do that?

I can't confirm if this was a problem in debug. Unfortunately I've had to roll back to 7.0.0, and have removed preview 5 - It's easily reproduced though, just fire up the standard Maui-BlazorHybrid template and try rendering to Android.

It works correctly in 7.0.0

hitchhiker commented 1 year ago

I re-installed 8.0.0 preview 5 to check, the WebView works in debug mode. It (after a removal / re-install of preview + work loads) still does not work in release (android or IOS). It does work as a Windows release however.

mkArtakMSFT commented 1 year ago

Related https://github.com/aspnet/AspNetCore-ManualTests/issues/1934

mkArtakMSFT commented 1 year ago

@grendello this is the same issue that we've already chatted about (linked above). Where do you want me to move this to (which repo)?

grendello commented 1 year ago

@mkArtakMSFT let's leave it here, since you can't easily move the issue to Xamarin.Android repo. I still don't know where the issue lies (it happens at a moment where all the JavaScript, Java and dotnet virtual machines are concurrently executing) so I guess leaving the issue here as as good as anywhere else

hitchhiker commented 1 year ago

If we can assume there's no workaround for this right now, would it be possible for someone to shed some light on the exposure AOT/compilation/packaging/deployment issues will be receiving in NET8?

The NET7 experience seems to (with respect) fall apart after a project reaches a certain level of complexity. Trim warnings appear throughout the whole MS framework, and even once they've been addressed the compiler (especially iOS) may or may not succeed intermittently. There are very few clear error messages, log files are filled with confusing and incomplete indications of what has gone wrong, and the whole process is quite unpredictable.. again, much of this fault may well lie with me, but I doubt all of it does.

This project (MAUI) is much needed, please do not consider this idle criticism. I am one of many who want to see MAUI succeed. Thank you in advance.

grendello commented 1 year ago

@hitchhiker A workaround is to set the MSBuild AndroidEnableMarshalMethods property to false. Marshal methods are a new mechanism in the Xamarin.Android release that will go out with NET8, for now it's experimental but enabled by default to get some testing outside our tests and codebase.

surayya-MS commented 1 year ago

@Eilon could you please look into this? Thanks!

grendello commented 1 year ago

As an update, we decided to disable marshal methods in Xamarin.Android for the NET8 release (thus, the AndroidEnableMarshalMethods property will default to false), so the problem won't show up when NET8 is out. The Blazor hang is very hard to trace, but we have a handful of leads and punting marshal methods to NET9 gives us the time to track and fix the issue properly.

mirza-developer commented 5 months ago

I have the same issue. In debug, we don't have any problem, but in release we have error below (from visual studio device log)

java.io.FileNotFoundException: wwwroot/_framework/blazor.webview.js

My repository: https://github.com/mirza-developer/Avhrm/tree/25-apk-settings

My device full logs: https://1drv.ms/x/s!AlRvlzbMVYhXpWtjFEPg8QRVY1aO?e=EP4sZj

Android device: Samsung S21 / SM-G991B Device Software: Android 14 / One UI 6 Visual studio 2022 version: 17.10.0 Windows version: 10.0.19045

RoiChen001 commented 2 months ago

I can repro this issue at Android platform on the latest 17.12.0 Preview 1.0(8.0.80 & 8.0.0-preview.5.8529).As the description says, it doesn't work properly in release mode.

LiamMorrow commented 2 months ago

I have seen similar issues with my app LiftLog. Reported on Android 11, but have seen it in Android 10 as well. What's interesting is that it is not all devices. Mostly it runs fine.

My build conditions for release

    <PropertyGroup Condition="'$(Configuration)' == 'Release'">
        <RunAOTCompilation>true</RunAOTCompilation>
        <AndroidStripILAfterAOT>true</AndroidStripILAfterAOT>
        <AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
        <EnableLLVM>true</EnableLLVM>
    </PropertyGroup>

https://liftlog.sentry.io/share/issue/10ce0ed1f9d54aff880bb0f65a859adc/

image image
mkArtakMSFT commented 1 month ago

Thanks everyone for all your input. We believe this issue was fixed by .NET 8 GA, but based on the last comment from @LiamMorrow it still happens. @LiamMorrow please share a minimal repro project so that we can investigate this further.

LiamMorrow commented 1 month ago

Thanks @mkArtakMSFT I'll see what I can do, however it's only been reported by users, I've never seen it myself so I might have trouble creating a minimal repro