From 7885c137a6776e729af88b9ab7b1f9949afe61ca Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Fri, 17 Jul 2026 11:42:08 +0200 Subject: [PATCH 1/3] [NativeAOT] Use trimmable typemap in PublishAot debug builds Select the typemap default from PublishAot instead of the resolved Android runtime so CoreCLR Debug builds of NativeAOT projects exercise the trimmable path. Preserve explicit typemap overrides and add a regression test.\n\nFollow-up to #12121.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>\nCopilot-Session: 4f9c5a7e-e73b-4cc2-8c1d-05c29795c5a4 --- ...soft.Android.Sdk.DefaultProperties.targets | 3 ++- .../Microsoft.Android.Sdk.NativeAOT.targets | 1 - .../TrimmableTypeMapBuildTests.cs | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets index b7a35e2e08d..d204d43abc5 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets @@ -38,7 +38,8 @@ class-parse XAJavaInterop1 <_AndroidJcwCodegenTarget Condition=" '$(_AndroidJcwCodegenTarget)' == '' and '$(_AndroidRuntime)' != 'NativeAOT' ">XAJavaInterop1 - <_AndroidTypeMapImplementation Condition=" '$(_AndroidTypeMapImplementation)' == '' and '$(_AndroidRuntime)' != 'NativeAOT' ">llvm-ir + <_AndroidTypeMapImplementation Condition=" '$(_AndroidTypeMapImplementation)' == '' and '$(PublishAot)' == 'true' ">trimmable + <_AndroidTypeMapImplementation Condition=" '$(_AndroidTypeMapImplementation)' == '' ">llvm-ir true true true diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets index 7511835ba25..f4f06041d4a 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets @@ -17,7 +17,6 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android. <_AndroidRuntimePackRuntime>NativeAOT <_AndroidUseWorkloadNativeLinker Condition=" '$(_AndroidUseWorkloadNativeLinker)' == '' ">true <_AndroidJcwCodegenTarget Condition=" '$(_AndroidJcwCodegenTarget)' == '' ">JavaInterop1 - <_AndroidTypeMapImplementation Condition=" '$(_AndroidTypeMapImplementation)' == '' ">trimmable true diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs index 310eaafa3f2..9a3c46cf0c3 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs @@ -36,6 +36,26 @@ public void Build_WithTrimmableTypeMap_Succeeds ([Values] bool isRelease, [Value AssertTrimmableTypeMapOutputs (intermediateDir); } + [Test] + public void Build_PublishAotProject_UsesTrimmableTypeMapForCoreClrDebug () + { + if (IgnoreUnsupportedConfiguration (AndroidRuntime.CoreCLR, release: false)) { + return; + } + + var proj = new XamarinAndroidApplicationProject { + IsRelease = false, + }; + proj.SetRuntime (AndroidRuntime.CoreCLR); + proj.SetProperty (KnownProperties.PublishAot, "true"); + + using var builder = CreateApkBuilder (); + Assert.IsTrue (builder.Build (proj, parameters: [ "_AndroidRuntime=CoreCLR" ]), "Build should have succeeded."); + + var intermediateDir = builder.Output.GetIntermediaryPath ("typemap"); + AssertTrimmableTypeMapOutputs (intermediateDir); + } + [Test] public void Build_WithTrimmableTypeMap_IncrementalBuild ([Values] bool isRelease, [Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime) { From 96b6b9e44c6cec5b3784559b08aeb01443bbf3f0 Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Fri, 17 Jul 2026 11:42:49 +0200 Subject: [PATCH 2/3] [NativeAOT] Explain PublishAot typemap selection Document why the typemap default must be selected from PublishAot instead of the resolved Android runtime. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4f9c5a7e-e73b-4cc2-8c1d-05c29795c5a4 --- .../targets/Microsoft.Android.Sdk.DefaultProperties.targets | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets index d204d43abc5..7f82eea7035 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets @@ -38,6 +38,7 @@ class-parse XAJavaInterop1 <_AndroidJcwCodegenTarget Condition=" '$(_AndroidJcwCodegenTarget)' == '' and '$(_AndroidRuntime)' != 'NativeAOT' ">XAJavaInterop1 + <_AndroidTypeMapImplementation Condition=" '$(_AndroidTypeMapImplementation)' == '' and '$(PublishAot)' == 'true' ">trimmable <_AndroidTypeMapImplementation Condition=" '$(_AndroidTypeMapImplementation)' == '' ">llvm-ir true From 8a1e79cca3cfdd657c7dfa7f16fa1529d42b539f Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Sat, 18 Jul 2026 02:03:03 +0200 Subject: [PATCH 3/3] [CoreCLR] Skip ILC for PublishAot inner-loop builds CoreCLR is used for Debug builds of PublishAot projects. Disable NativeCompilationDuringPublish before the SDK imports ILCompiler targets so these builds remain on the CoreCLR path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3deb271e-aea1-4ba1-bad5-2cdc4cf847bb --- .../targets/Microsoft.Android.Sdk.CoreCLR.targets | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.CoreCLR.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.CoreCLR.targets index 27a57454aeb..8e6c5969f05 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.CoreCLR.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.CoreCLR.targets @@ -10,6 +10,8 @@ This file contains the CoreCLR-specific MSBuild logic for .NET for Android. <_AndroidRuntimePackRuntime>CoreCLR + + false