[Java.Interop.Tools.TypeNameMappings] fix trimmer warnings #1194
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: https://github.com/xamarin/xamarin-android/blob/e987ac458536e59a8329a06d5c5d5f4d4ea2c6b6/src/Mono.Android/Mono.Android.csproj#L69-L71
In xamarin/xamarin-android, we import the source for
Java.Interop.Tools.TypeNameMappings\JavaNativeTypeManager.cs, and unfortunately there are some trimmer warnings:From the code:
It appears we can instead look for
IJavaPeerableand use trim-safe behavior instead:I also cached the
Type.GetType()call withLazy<T>.However, in some cases we run this code under an MSBuild context. In
this case, we don't have
Java.Interop.dllto load, so we shouldinstead use:
To catch warnings in this project going forward:
Multi-target to
netstandard2.0andnet8.0using$(DotNetTargetFramework).netstandard2.0is used for MSBuild-task assemblies inside VS.Enable trimmer warnings for
net8.0As I targeted
net8.0, various null-reference-type warnings appeared, which I also fixed.