Commit 56b7eeb
authored
[Java.Interop.Tools.TypeNameMappings] fix trimmer warnings (#1194)
Context: https://github.com/xamarin/xamarin-android/blob/e987ac458536e59a8329a06d5c5d5f4d4ea2c6b6/src/Mono.Android/Mono.Android.csproj#L69-L71
In xamarin/xamarin-android's `Mono.Android.dll`, we [import][0]
`Java.Interop.Tools.TypeNameMappings\JavaNativeTypeManager.cs`, and
unfortunately that causes some trimmer warnings:
external\Java.Interop\src\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings\JavaNativeTypeManager.cs(182,9):
error IL2070: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'System.Type.GetInterfaces()'.
The parameter 'type' of method 'Java.Interop.Tools.TypeNameMappings.JavaNativeTypeManager.ToJniName(Type, ExportParameterKind)'
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.
From the code:
if (!type.GetInterfaces ().Any (t => t.FullName == "Android.Runtime.IJavaObject"))
It appears we can instead look for `IJavaPeerable` and use trim-safe
behavior instead:
if (Type.GetType ("Java.Interop.IJavaPeerable, Java.Interop", throwOnError: true)
.IsAssignableFrom (type))
I also cache the `Type.GetType()` call with `Lazy<T>`.
However, in some cases we run this code under an MSBuild context.
In this case, we don't have `Java.Interop.dll` to load, so we should
instead use a variation on the previous code:
type.GetInterfaces ().Any (t => t.FullName == "Java.Interop.IJavaPeerable");
To catch warnings in this project going forward:
* Multi-target to `netstandard2.0` and `net8.0` using
`$(DotNetTargetFramework)`.
`netstandard2.0` is used for MSBuild-task assemblies inside VS.
* Enable trimmer warnings for `net8.0`.
Additionally, as I targeted `net8.0`, various null-reference-type
warnings appeared, which I also fixed.
[0]: https://github.com/xamarin/xamarin-android/blob/e199d62210bfb666595d95ca60579c5c766be1d6/src/Mono.Android/Mono.Android.csproj#L69-L711 parent c825dca commit 56b7eeb
File tree
6 files changed
+37
-11
lines changed- src
- Java.Interop.Tools.JavaCallableWrappers
- Java.Interop.Tools.JavaCallableWrappers.Adapters
- Java.Interop.Tools.JavaCallableWrappers.CallableWrapperMembers
- Java.Interop.Tools.JavaCallableWrappers
- Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings
6 files changed
+37
-11
lines changedLines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
547 | 547 | | |
548 | 548 | | |
549 | 549 | | |
550 | | - | |
| 550 | + | |
551 | 551 | | |
552 | 552 | | |
553 | 553 | | |
554 | 554 | | |
555 | 555 | | |
556 | | - | |
| 556 | + | |
557 | 557 | | |
558 | 558 | | |
559 | 559 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
318 | | - | |
| 318 | + | |
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
| |||
Lines changed: 14 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
5 | 10 | | |
6 | 11 | | |
7 | 12 | | |
8 | 13 | | |
9 | 14 | | |
| 15 | + | |
10 | 16 | | |
11 | 17 | | |
12 | 18 | | |
| |||
17 | 23 | | |
18 | 24 | | |
19 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
20 | 32 | | |
21 | 33 | | |
22 | 34 | | |
23 | 35 | | |
24 | 36 | | |
25 | 37 | | |
26 | | - | |
| 38 | + | |
27 | 39 | | |
28 | 40 | | |
29 | 41 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
| 182 | + | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
| 193 | + | |
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| |||
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
269 | | - | |
| 269 | + | |
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
| |||
Lines changed: 16 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
182 | | - | |
| 181 | + | |
183 | 182 | | |
184 | 183 | | |
185 | 184 | | |
186 | 185 | | |
187 | 186 | | |
188 | 187 | | |
189 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
190 | 204 | | |
191 | 205 | | |
192 | 206 | | |
| |||
0 commit comments