[HybridWebView] fix trimmer warnings on Android #24744
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: #23769
Context: dotnet/android#9300
026e046 introduced
HybridWebView
, which unfortunately introduces trimmer warnings in thedotnet new maui
project template:This is due to usage of
Java.Interop.ExportAttribute
:Java.Interop.ExportAttribute
makes heavy usage of unbounded System.Reflection, System.Reflection.Emit, etc. for it to be able to work. It brings in an additional assemblyMono.Android.Export.dll
as well.It is inherently trimming unsafe, but how did it get through these tests?
maui/src/TestUtils/src/Microsoft.Maui.IntegrationTests/AndroidTemplateTests.cs
Lines 50 to 61 in 08ff124
This slipped through, unfortunately, as we had missed solving all the trimmer warnings in
Mono.Android.Export.dll
! dotnet/android#9300 aims to fix that.After dotnet/android#9300, new trimming warnings specific to .NET MAUI will surface such as the one above.
But we can easily replace
[Export]
by:Define a Java interface & create a binding for it in C#, we already have
maui.aar
setup for this.We can simply implement the interface in C# and remove
[Export]
.Lastly, I fixed some of the defaults in
Metadata.xml
, it didn't look like we were automatically making Java interfacesinternal
. It looks like we probably madeImageLoaderCallback
public by mistake.