Commit 1275ade
authored
[TrimmableTypeMap] Fix [Export] JNI signature mapping for non-primitive parameter types (#11051)
## Problem
The scanner's `ManagedTypeToJniDescriptor()` method maps managed types to JNI descriptors for `[Export]` method signatures. It correctly handles primitives (`bool` → `Z`, `int` → `I`, etc.) and `string` → `Ljava/lang/String;`, but **falls back to `Ljava/lang/Object;` for all other types**. This means `[Export]` methods with parameters like `Android.Graphics.Bitmap`, `Android.Views.View`, or any custom Java-bound type get incorrect JNI signatures in the generated JCW, causing `NoSuchMethodError` at runtime.
## Fix
`ManagedTypeToJniDescriptor()` now resolves Java-bound types by looking up their `[Register]` attribute via the existing `TryResolveJniObjectDescriptor()` infrastructure (already used by the constructor signature path), falling back to `Ljava/lang/Object;` only for types that truly cannot be resolved.
## Changes Made
- **`ManagedTypeToJniDescriptor`** — Added `TryResolveJniObjectDescriptor` call before the `Ljava/lang/Object;` fallback; converted from `static` to instance to access the assembly cache.
- **`BuildJniSignatureFromManaged`, `ParseExportAttribute`, `ParseExportFieldAsMethod`, `TryGetMethodRegisterInfo`, `CollectExportField`** — Converted from `static` to instance (transitively need the assembly cache for type resolution).
- **`ExportWithJavaBoundParams`** test type — Added with three `[Export]` methods taking `Android.Views.View` parameters.
- **`Scan_ExportMethod_ResolvesJavaBoundParameterTypes`** test theory — Verifies correct JNI signatures for `[Export]` methods with non-primitive Java-bound parameter types.
- **`ExportFieldTests`** — Updated assertion to expect the correctly resolved type name (`my.app.ExportFieldExample`) instead of the previous incorrect `java.lang.Object` fallback.
## Testing
- All 303 TrimmableTypeMap unit tests pass, including 3 new test cases.1 parent 96d619c commit 1275ade
File tree
4 files changed
+47
-10
lines changed- src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner
- tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests
- Generator
- Scanner
- TestFixtures
4 files changed
+47
-10
lines changedLines changed: 15 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
956 | 956 | | |
957 | 957 | | |
958 | 958 | | |
959 | | - | |
| 959 | + | |
960 | 960 | | |
961 | 961 | | |
962 | 962 | | |
| |||
1006 | 1006 | | |
1007 | 1007 | | |
1008 | 1008 | | |
1009 | | - | |
| 1009 | + | |
1010 | 1010 | | |
1011 | 1011 | | |
1012 | 1012 | | |
| |||
1050 | 1050 | | |
1051 | 1051 | | |
1052 | 1052 | | |
1053 | | - | |
| 1053 | + | |
1054 | 1054 | | |
1055 | 1055 | | |
1056 | 1056 | | |
| |||
1067 | 1067 | | |
1068 | 1068 | | |
1069 | 1069 | | |
1070 | | - | |
| 1070 | + | |
1071 | 1071 | | |
1072 | 1072 | | |
1073 | 1073 | | |
| |||
1080 | 1080 | | |
1081 | 1081 | | |
1082 | 1082 | | |
1083 | | - | |
1084 | | - | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
1085 | 1086 | | |
1086 | | - | |
| 1087 | + | |
1087 | 1088 | | |
1088 | 1089 | | |
1089 | 1090 | | |
| |||
1094 | 1095 | | |
1095 | 1096 | | |
1096 | 1097 | | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
1097 | 1104 | | |
1098 | 1105 | | |
1099 | 1106 | | |
| |||
1515 | 1522 | | |
1516 | 1523 | | |
1517 | 1524 | | |
1518 | | - | |
| 1525 | + | |
1519 | 1526 | | |
1520 | 1527 | | |
1521 | 1528 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
| 23 | + | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
56 | 69 | | |
57 | 70 | | |
58 | 71 | | |
| |||
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
287 | 304 | | |
288 | 305 | | |
289 | 306 | | |
| |||
0 commit comments