-
Notifications
You must be signed in to change notification settings - Fork 531
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
[Mono.Android] fix a set of the "easiest" trimmer warnings #8731
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Context: dotnet#5652 Introduce a new `trim-analyzers.targets` file to be used in this repo: 1. Enables appropriate analyzers. 2. `$(ILLinkTreatWarningsAsErrors)` only does anything in builds that would run `ILLink`, such as an application build. Useful to be here. 3. List all the explicit ILLink and AOT warnings, so that they trigger build errors. Eventually we should be able to import this file for `Mono.Android.csproj`. Fixing the following so far: ~~ TypeConverter ~~ Context: https://source.dot.net/#System.ComponentModel.TypeConverter/System/ComponentModel/TypeConverter.cs,226 src\Mono.Android\System.Drawing\SizeFConverter.cs(121,49): error IL2046: Base member 'System.ComponentModel.TypeConverter.GetProperties(ITypeDescriptorContext, Object, Attribute[])' with 'RequiresUnreferencedCodeAttribute' has a derived member 'System.Drawing.SizeFConverter.GetProperties(ITypeDescriptorContext, Object, Attribute[])' without 'RequiresUnreferencedCodeAttribute'. 'RequiresUnreferencedCodeAttribute' annotations must match across all interface implementations or overrides. Various `TypeConverter` implementations need to specify `[RequiresUnreferencedCode]` to match the base type. ~~ ColorValueMarshaler & IJavaObjectValueMarshaler ~~ Context: dotnet/java-interop@7d1e705 From the trimmer warnings solved in `Java.Interop.dll`, we need to bring these changes forward to any `*Marshaler` types. ~~ AndroidClientHandler ~~ 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.NonPublicFields' in call to 'System.Type.GetField(String, BindingFlags)'. The return value of method 'System.Collections.IEnumerator.Current.get' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. This class had a loop that was not trimming safe: for (var type = GetType (); type != null; type = type.BaseType) { field = type.GetField (fieldName, BindingFlags.Instance | BindingFlags.NonPublic); if (field != null) break; } If we *look* at the actual base types of `AndroidClientHandler`, we can simplify this loop to something that *is* trimming safe: const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic; FieldInfo? field = typeof (HttpClientHandler).GetField (fieldName, flags) ?? typeof (HttpMessageHandler).GetField (fieldName, flags); There should be no need to iterate *beyond* `HttpMessageHandler`, the code is looking for this field: https://github.com/dotnet/runtime/blob/135fec006e727a31763271984cd712f1659ccbd3/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.cs#L25
jonathanpeppers
commented
Feb 21, 2024
grendello
added a commit
that referenced
this pull request
Feb 28, 2024
* main: Bump to xamarin/xamarin-android-tools/main@37d79c9 (#8752) Bump to dotnet/installer@d070660282 9.0.100-preview.3.24126.2 (#8763) Bump to xamarin/java.interop/main@14a9470 (#8766) $(AndroidPackVersionSuffix)=preview.3; net9 is 34.99.0.preview.3 (#8765) [Mono.Android] Do not dispose request content stream in AndroidMessageHandler (#8764) Bump com.android.tools:r8 from 8.2.42 to 8.2.47 (#8761) [Mono.Android] fix a set of the "easiest" trimmer warnings (#8731) Bump to dotnet/installer@0a73f814e1 9.0.100-preview.2.24122.3 (#8716) [ci] Always run the MAUI test job (#8750) Add a property required by #8478 (#8749) [xamarin-android-tools] import $(LibZipSharpVersion) value (#8738) Bump to xamarin/Java.Interop/main@c825dcad (#8701) Bump to xamarin/monodroid@cb01503327 (#8742) Bump to xamarin/Java.Interop/main@ae65609 (#8744) Bring in changes from PR #8478 (#8727) [xaprepare] Make 7zip work with "dangerous" symlinks in ZIPs (#8737) Bump NDK to r26c (#8732) Debugging MSBuild Tasks (#8730)
grendello
added a commit
that referenced
this pull request
Feb 28, 2024
* main: [Mono.Android] fix a set of the "easiest" trimmer warnings (#8731) Bump to dotnet/installer@0a73f814e1 9.0.100-preview.2.24122.3 (#8716)
grendello
added a commit
that referenced
this pull request
Mar 1, 2024
* main: [tests] fix duplicate sources in `NuGet.config` (#8772) Bump to xamarin/monodroid@e13723e701 (#8771) Bump to xamarin/xamarin-android-tools/main@37d79c9 (#8752) Bump to dotnet/installer@d070660282 9.0.100-preview.3.24126.2 (#8763) Bump to xamarin/java.interop/main@14a9470 (#8766) $(AndroidPackVersionSuffix)=preview.3; net9 is 34.99.0.preview.3 (#8765) [Mono.Android] Do not dispose request content stream in AndroidMessageHandler (#8764) Bump com.android.tools:r8 from 8.2.42 to 8.2.47 (#8761) [Mono.Android] fix a set of the "easiest" trimmer warnings (#8731) Bump to dotnet/installer@0a73f814e1 9.0.100-preview.2.24122.3 (#8716)
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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: #5652
Introduce a new
trim-analyzers.targets
file to be used in this repo:Enables appropriate analyzers.
$(ILLinkTreatWarningsAsErrors)
only does anything in builds that would runILLink
, such as an application build. Useful to be here.List all the explicit ILLink and AOT warnings, so that they trigger build errors.
Eventually we should be able to import this file for
Mono.Android.csproj
.Fixing the following so far:
TypeConverter
Context: https://source.dot.net/#System.ComponentModel.TypeConverter/System/ComponentModel/TypeConverter.cs,226
Various
TypeConverter
implementations need to specify[RequiresUnreferencedCode]
to match the base type.ColorValueMarshaler & IJavaObjectValueMarshaler
Context: dotnet/java-interop@7d1e705
From the trimmer warnings solved in
Java.Interop.dll
, we need to bring these changes forward to any*Marshaler
types.AndroidClientHandler
This class had a loop that was not trimming safe:
If we look at the actual base types of
AndroidClientHandler
, we can simplify this loop to something that is trimming safe:There should be no need to iterate beyond
HttpMessageHandler
, the code is looking for this field:https://github.com/dotnet/runtime/blob/135fec006e727a31763271984cd712f1659ccbd3/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.cs#L25