-
Notifications
You must be signed in to change notification settings - Fork 573
[TrimmableTypeMap][NativeAOT] Auto-detect and scan runtime-only assemblies (fixes stripped runtime ACWs) #11982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,38 @@ public void Build_WithTrimmableTypeMap_IncrementalBuild ([Values] bool isRelease | |
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public void Build_WithTrimmableTypeMap_KeepsNativeAotRuntimeHostAcws () | ||
| { | ||
| const bool isRelease = true; | ||
| if (IgnoreUnsupportedConfiguration (AndroidRuntime.NativeAOT, release: isRelease)) { | ||
| return; | ||
| } | ||
|
|
||
| var proj = new XamarinAndroidApplicationProject { | ||
| IsRelease = isRelease, | ||
| LinkTool = "r8", | ||
| }; | ||
| proj.SetRuntime (AndroidRuntime.NativeAOT); | ||
| proj.SetProperty ("_AndroidTypeMapImplementation", "trimmable"); | ||
|
|
||
| using var builder = CreateApkBuilder (); | ||
| Assert.IsTrue (builder.Build (proj), "Build should have succeeded."); | ||
|
|
||
| var dexFile = builder.Output.GetIntermediaryPath (Path.Combine ("android", "bin", "classes.dex")); | ||
| FileAssert.Exists (dexFile); | ||
|
|
||
| // Regression test: the NativeAOT runtime host assembly (Microsoft.Android.Runtime.NativeAOT) is | ||
| // resolved only in the per-RID inner build, so the RID-independent outer-build trimmable typemap | ||
| // generator never scanned it. Its only Java Callable Wrapper type, UncaughtExceptionMarshaler, | ||
| // therefore had no JCW and no typemap entry -> the runtime ACW is absent from classes.dex and the | ||
| // app crashes at startup in JavaInteropRuntime.init (setDefaultUncaughtExceptionHandler). A | ||
| // reference assembly for the host is now shipped in the SDK pack and fed to the generator. The JCW | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Rule: Remove stale comments (Postmortem |
||
| // name is CRC-hashed (e.g. `scrc64...UncaughtExceptionMarshaler`), so match on the type name suffix. | ||
| Assert.IsTrue (DexUtils.ContainsClass ("UncaughtExceptionMarshaler;", dexFile, AndroidSdkPath), | ||
| $"`{dexFile}` should include the UncaughtExceptionMarshaler runtime ACW."); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Build_WithTrimmableTypeMap_DeletesStaleGeneratedJavaSourcesAndCopies () | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 💡 MSBuild targets — This includes every runtime-pack managed DLL, including the .NET/BCL runtime pack (
Microsoft.NETCore.App.Runtime.*), whereas the sibling_ResolveRuntimeOnlyAssembliesForTypeMapdeliberately filters toMicrosoft.Android.Runtimeand excludes the BCL. It is harmless today — these names only feed theRemoveon_TrimmableTypeMapUnmanagedEntryPointAssemblyNames, and BCL assemblies have no generated_*.TypeMapDLL to remove — but the asymmetry between the two targets is a maintenance trap and inflates the item group with hundreds of no-op BCL names. Consider matching the resolve target'sStartsWith('Microsoft.Android.Runtime')filter here, or add a note explaining why the broader set is intentional.Rule: Consistency with sibling targets