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

Make MAUI blazor which required android api 24 compatible to api 21 #8375

Closed
wants to merge 3 commits into from
Closed

Conversation

wch1618
Copy link

@wch1618 wch1618 commented Jun 28, 2022

Description of Change

Using androidx.webkit.WebViewCompat to make AndroidWebKitWebViewManager from android api 23 compatible to api 21 or more low.

@wch1618 wch1618 requested a review from a team as a code owner June 28, 2022 08:27
@dnfadmin
Copy link

dnfadmin commented Jun 28, 2022

CLA assistant check
All CLA requirements met.

@jfversluis jfversluis added the area/blazor 🕸️ Blazor Hybrid / Desktop, BlazorWebView label Jun 28, 2022
Comment on lines -19 to +20
[SupportedOSPlatform("android23.0")]
[SupportedOSPlatform("android21.0")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove these attributes now since we have a min version in .NET itself that is 21. .NET 6 does not run on lower than 21.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

@@ -108,6 +109,7 @@ public override void OnMessage(WebMessagePort? port, WebMessage? message)

_onMessageReceived(message.Data);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line

@javiercn
Copy link
Member

@wch1618 would you mind filing an issue first explaining the motivation for the change as well as the impact so that the team can assess whether or not we want to take this change in?

@SteveSandersonMS
Copy link
Member

Agreed with @javiercn

It would also be great to hear from someone on the MAUI team who has worked on Android support (and perhaps added the existing AndroidX references), cc @jonathanpeppers @jpobst:

  • Are there any drawbacks or risks we should know about?
  • If there were no drawbacks/risks, what's the brief explanation of why we didn't already have MAUI webviews working on Android 21?

If it's safe and doesn't impact perf/stability/etc., then it's certainly an advantage to get support for a wider range of devices!

Hope that's OK - we on the Blazor team don't have as much experience as some others in MAUI about the lower-level details of Android support.

Comment on lines +64 to +67
<PackageReference
Update="Xamarin.AndroidX.WebKit"
Version="1.4.0.8"
/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is an Update, how does this line do anything? It must already be a transitive dependency, and we can remove it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javiercn would you mind filing an issue first explaining the motivation for the change as well as the impact so that the team can assess whether or not we want to take this change in?

Please forgive me for not having time to reply a few days ago.

This is not necessary, but just a suggestion for the following reasons.

  1. From Android API 24 to 23, it is not difficult for Android. They are all official.

  2. API 21 app will run on approximately 98.6% of devices, and API 24 app only has 91.7%. The is from Android studio.

  3. Using androidx.webkit increases the size of Android installation package a little and the performance loss is almost negligible.

  4. It makes the Android device compatibility of Maui Blazor consistent with Maui.

  5. My test method is temporarily modified the namespace of Microsoft.AspNetCore.Components.WebView.Maui.csproj and only compile it with min Android API 21, so that it can be directly added to the Maui blazor app project, and then tested on the real machine of Android 5(API 21). The startup speed is acceptable, which is 40% faster than blazor WebAssembly. This is stupid, but simple and effective.

@jonathanpeppers
Copy link
Member

The AndroidX libraries are a "polyfill" for making your app run on old Android versions. I would recommend using this for BlazorWebView if things break on API 21. Does someone know what the actual problem is? It's common for Android to add something new, so I wouldn't be surprised if some method is used that was introduced in 23.

However, to know if this PR is going to work, I would have someone manually test this change on Android emulators of different versions.

@jonathanpeppers
Copy link
Member

@rmarinho
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@TanayParikh
Copy link
Contributor

TanayParikh commented Jun 28, 2022

We'll also need to update the min Android API version in the Maui blazor csproj, project template (#7342)

@mattleibow
Copy link
Member

Does someone know what the actual problem is?

Yeah, Blazor is only supported on Android API 23+ but the rest of MAUI and .NET support API 21+.

@mattleibow
Copy link
Member

Current error:

D:\a_work\1\s\src\BlazorWebView\src\Maui\Android\AndroidWebKitWebViewManager.cs(7,16): error CS0234: The type or namespace name 'WebKit' does not exist in the namespace 'AndroidX' (are you missing an assembly reference?) [D:\a_work\1\s\src\BlazorWebView\src\Maui\Microsoft.AspNetCore.Components.WebView.Maui.csproj]

Did this compile locally?

@mattleibow
Copy link
Member

We probably also need to enable device tests on the older platforms too: https://github.com/dotnet/maui/blob/main/eng/pipelines/device-tests.yml#L110

@wch1618
Copy link
Author

wch1618 commented Jul 1, 2022

As for the reply to the failure of the test, I only modified the platform code related to Android, which has nothing to do with MacOS and windows. I have tried to check the details of the test error to see whether it can be handled, but unfortunately, the details did not describe not clearly enough.

Other small problems, such as redundant lines and redundant attributes, please help remove them.

@wch1618 wch1618 closed this Jul 5, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/blazor 🕸️ Blazor Hybrid / Desktop, BlazorWebView
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants