Commit 36b07f1
[TrimmableTypeMap] Fix stale legacy JCW contamination when switching typemap flavors
When switching MonoAndroidTypeMapFlavor between legacy and trimmable
without a clean build, stale legacy JCWs with Runtime.register(typeName,
klass, methods) calls persisted in the android/src/ intermediate
directory alongside trimmable JCWs that only use Runtime.registerNatives().
Both got compiled into the APK, causing the legacy registration path to
execute at runtime — a path incompatible with trimming.
Root cause: the trimmable JCW generator wrote to typemap/java/ and then
copied to android/src/, but never cleaned android/src/ first. Legacy
JCWs with different package names survived the copy overlay.
Three fixes:
1. Write trimmable JCWs directly to _AndroidIntermediateJavaSourceDirectory
(android/src/) instead of a separate typemap/java/ directory, eliminating
the copy step entirely. This is the same directory that _FindJavaStubFiles
globs from, so no files can be missed or stale.
2. Add MonoAndroidTypeMapFlavor to the build properties cache so switching
between legacy and trimmable triggers _CleanIntermediateIfNeeded,
removing all stale artifacts from the previous flavor.
3. Always wire registerJniNativesFn so that if a stale JCW somehow calls
Runtime.register(), TrimmableTypeMapTypeManager.RegisterNativeMembers
throws UnreachableException with a clear diagnostic instead of the C++
side silently dropping the call.
Also adds a unit test verifying trimmable JCWs never emit Runtime.register().
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent c2bdc5b commit 36b07f1
5 files changed
Lines changed: 16 additions & 16 deletions
File tree
- src
- Mono.Android
- Android.Runtime
- Microsoft.Android.Runtime
- Xamarin.Android.Build.Tasks
- Microsoft.Android.Sdk/targets
- tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | | - | |
182 | | - | |
183 | | - | |
| 181 | + | |
184 | 182 | | |
185 | 183 | | |
186 | 184 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
Lines changed: 1 addition & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
| |||
55 | 54 | | |
56 | 55 | | |
57 | 56 | | |
58 | | - | |
| 57 | + | |
59 | 58 | | |
60 | 59 | | |
61 | 60 | | |
| |||
99 | 98 | | |
100 | 99 | | |
101 | 100 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | 101 | | |
112 | 102 | | |
113 | 103 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
981 | 981 | | |
982 | 982 | | |
983 | 983 | | |
| 984 | + | |
984 | 985 | | |
985 | 986 | | |
986 | 987 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
137 | 147 | | |
138 | 148 | | |
139 | 149 | | |
| |||
0 commit comments