Commit ed92bec
authored
[TrimmableTypeMap] Generator correctness fixes (#11988)
Java.Interop.ManagedPeer is a reflection-based helper marked
[RequiresUnreferencedCode] ("Uses reflection to find constructors and
invoke them."). The trimmable type map generator emitted a proxy for it
(_TypeMap.Proxies.Java_Interop_ManagedPeer_Proxy) whose constructor
references ManagedPeer's constructors, producing two IL2026 trim
warnings, aggregated by ILC into:
IL2104: Assembly '_Java.Interop.TypeMap' produced trim warnings
Because the default NativeAOT type map is now trimmable, this surfaced as
a real MSBuild warning and broke NativeAOT tests that assert no warnings
(e.g. BuildWithJavaToolOptions).
ManagedPeer is not supported by the trimmable type map: on the trimmable
path native registration goes through IAndroidCallableWrapper.RegisterNatives
and ManagedPeerNativeRegistration is disabled, so ManagedPeer is never
activated via the type map. Exclude it in the scanner so no proxy is
emitted.
Verified on an arm64 emulator: the HelloWorld NativeAOT (trimmable)
sample now builds with 0 warnings and still launches to MainActivity.
### [TrimmableTypeMap] Emit <layout> element for the [Layout] attribute
The trimmable manifest generator already had ComponentElementBuilder support for
a <layout> child element, but the scanner never populated
ComponentInfo.LayoutProperties, so [Layout(...)] on an activity produced no
<layout> element (LayoutAttributeElement failed on NativeAOT).
Parse the [Layout] attribute's named properties in AssemblyIndex.ParseAttributes
(collected separately to tolerate attribute ordering, like [IntentFilter] and
[MetaData]) and flow them through TypeAttributeInfo.LayoutProperties into
ComponentInfo.LayoutProperties.
### [TrimmableTypeMap] Emit XA1010 for invalid $(AndroidManifestPlaceholders)
ManifestGenerator.ApplyPlaceholders already invoked a WarnInvalidPlaceholder
callback for placeholder entries without '=', but the callback was never wired
up, so the trimmable path silently dropped the XA1010 warning the legacy
ManifestDocument emits (ManifestPlaceHoldersXA1010 failed on NativeAOT).
Add ITrimmableTypeMapLogger.LogInvalidManifestPlaceholderWarning (logging
XA1010 from the MSBuild logger) and wire the ManifestGenerator instance's
WarnInvalidPlaceholder to it. The rooting-only PrepareManifestForRooting pass
stays silent so the warning is not emitted twice.
### [TrimmableTypeMap] Make generated typemap assemblies byte-deterministic
PEAssemblyBuilder.WritePE let ManagedPEBuilder fall back to a time-based PE
content id, so every regeneration of a typemap assembly produced different bytes
(different PE TimeDateStamp) even for identical input — the MVID was already
deterministic, but the image was not.
That churn broke incremental packaging on NativeAOT: an SDK CoreCompile rerun
(e.g. touching a .csproj.user file, which the SDK treats as a compile input)
rewrites the app assembly, reruns _GenerateTrimmableTypeMap, and — because the
regenerated *.TypeMap.dll got a fresh timestamp — forced _BuildApkEmbed to
repackage and _Sign to re-sign (CSProjUserFileChanges failed on NativeAOT).
Supply a deterministic content-id provider (SHA-256 over the serialized image)
so identical input yields byte-identical output; CopyIfStreamChanged then keeps
the existing file/timestamp and downstream targets stay incremental.
### [TrimmableTypeMap] Resolve java/lang/Object to Java.Lang.Object
For a JNI name mapped by multiple managed types (an alias group), the trimmable type map's
GetTypeForSimpleReference returns the first (index [0]) alias. Order the aliases to match the
native runtime's java->managed selection (clr_typemap_java_to_managed / monovm_typemap_java_to_managed,
built by NativeTypeMappingData): the Mono.Android module is processed first and the first managed
type to claim a Java name wins. So java/lang/Object must resolve to Java.Lang.Object (Mono.Android),
not Java.Interop.JavaObject (Java.Interop).
Order alias peers Mono.Android-assembly-first, with an ordinal managed-name tiebreak for
deterministic proxy naming.1 parent 6771716 commit ed92bec
12 files changed
Lines changed: 128 additions & 6 deletions
File tree
- src
- Microsoft.Android.Sdk.TrimmableTypeMap
- Generator
- Scanner
- Xamarin.Android.Build.Tasks/Tasks
- tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
48 | | - | |
| 47 | + | |
49 | 48 | | |
50 | 49 | | |
51 | 50 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
516 | 516 | | |
517 | 517 | | |
518 | 518 | | |
519 | | - | |
| 519 | + | |
520 | 520 | | |
521 | 521 | | |
522 | 522 | | |
| |||
Lines changed: 14 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
106 | 105 | | |
107 | | - | |
| 106 | + | |
108 | 107 | | |
109 | 108 | | |
110 | 109 | | |
| |||
141 | 140 | | |
142 | 141 | | |
143 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
144 | 156 | | |
145 | 157 | | |
146 | 158 | | |
| |||
Lines changed: 19 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
110 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
111 | 115 | | |
112 | 116 | | |
113 | 117 | | |
114 | 118 | | |
115 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
116 | 134 | | |
117 | 135 | | |
118 | 136 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
Lines changed: 24 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| |||
214 | 215 | | |
215 | 216 | | |
216 | 217 | | |
| 218 | + | |
| 219 | + | |
217 | 220 | | |
218 | 221 | | |
219 | 222 | | |
| |||
232 | 235 | | |
233 | 236 | | |
234 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
235 | 241 | | |
236 | 242 | | |
237 | 243 | | |
| |||
425 | 431 | | |
426 | 432 | | |
427 | 433 | | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
428 | 446 | | |
429 | 447 | | |
430 | 448 | | |
| |||
712 | 730 | | |
713 | 731 | | |
714 | 732 | | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
715 | 739 | | |
716 | 740 | | |
717 | 741 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
277 | 281 | | |
278 | 282 | | |
279 | 283 | | |
| |||
286 | 290 | | |
287 | 291 | | |
288 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
289 | 297 | | |
290 | 298 | | |
291 | 299 | | |
| |||
2528 | 2536 | | |
2529 | 2537 | | |
2530 | 2538 | | |
| 2539 | + | |
2531 | 2540 | | |
2532 | 2541 | | |
2533 | 2542 | | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| 158 | + | |
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
Lines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
108 | 127 | | |
109 | 128 | | |
110 | 129 | | |
| |||
385 | 404 | | |
386 | 405 | | |
387 | 406 | | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
388 | 425 | | |
389 | 426 | | |
390 | 427 | | |
| |||
0 commit comments