From 10ba93691db4cd6dc3b3caf7072e076dec8a77f2 Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Tue, 18 Aug 2026 16:34:29 +0200 Subject: [PATCH 1/5] [build] Use CoreCLR for Debug PublishAot builds Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ecfa1706-25e7-415f-a03e-af27f65164fc --- .../building-apps/build-properties.md | 9 +++--- ...oft.Android.Sdk.AssemblyResolution.targets | 1 + ...soft.Android.Sdk.DefaultProperties.targets | 6 ++-- .../TrimmableTypeMapBuildTests.cs | 31 +++++++++++++++++-- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Documentation/docs-mobile/building-apps/build-properties.md b/Documentation/docs-mobile/building-apps/build-properties.md index 31334e5ec7e..ddf4d2d9bbc 100644 --- a/Documentation/docs-mobile/building-apps/build-properties.md +++ b/Documentation/docs-mobile/building-apps/build-properties.md @@ -1248,8 +1248,8 @@ This property is obsolete and should not be used. An enum-style property that selects the type map implementation. Valid values are `llvm-ir` and `trimmable`. -The default value is `llvm-ir` when using CoreCLR and `trimmable` when using -NativeAOT. +The default value is `trimmable` when using CoreCLR or NativeAOT and `llvm-ir` +when using MonoVM. ## AndroidUseApkSigner @@ -1894,8 +1894,9 @@ Xamarin.Android. This is the same property used for [Blazor WASM][blazor]. A boolean property that controls whether Android applications use the Mono runtime instead of CoreCLR. Set this property to `true` to use -Mono or `false` to use CoreCLR. `$(PublishAot)` takes precedence and -selects NativeAOT when set to `true`. +Mono or `false` to use CoreCLR. `$(PublishAot)` takes precedence. Debug +builds continue to use CoreCLR, while Release builds and publish operations +use NativeAOT. This property defaults to `true` in .NET 10 and earlier, so Android applications use Mono. In .NET 11 and later, it defaults to `false`, diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets index 2b056f02870..beda49200da 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets @@ -153,6 +153,7 @@ _ResolveAssemblies MSBuild target. ;DesignTimeBuild=$(DesignTimeBuild) ;AppendRuntimeIdentifierToOutputPath=true ;ResolveAssemblyReferencesFindRelatedSatellites=false + ;NativeCompilationDuringPublish=$(NativeCompilationDuringPublish) ;SkipCompilerExecution=true ;_OuterIntermediateAssembly=@(IntermediateAssembly) ;_OuterIntermediateSatelliteAssembliesWithTargetPath=@(IntermediateSatelliteAssembliesWithTargetPath) 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 af654a3b23f..33323b21ba2 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 @@ -29,10 +29,11 @@ See: https://github.com/dotnet/sdk/blob/955c0fc7b06e2fa34bacd076ed39f61e4fb61716/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets#L16 --> <_GetChildProjectCopyToPublishDirectoryItems>false - <_AndroidRuntime Condition=" '$(PublishAot)' == 'true' ">NativeAOT + <_AndroidRuntime Condition=" '$(PublishAot)' == 'true' and ('$(Configuration)' == 'Release' or '$(_IsPublishing)' == 'true') ">NativeAOT <_AndroidRuntime Condition=" '$(PublishAot)' != 'true' and '$(UseMonoRuntime)' == 'true' ">MonoVM <_AndroidRuntime Condition=" '$(_AndroidRuntime)' == '' ">CoreCLR true + false $(AndroidMinimumSupportedApiLevel) @@ -44,7 +45,8 @@ class-parse XAJavaInterop1 <_AndroidJcwCodegenTarget Condition=" '$(_AndroidJcwCodegenTarget)' == '' and '$(_AndroidRuntime)' != 'NativeAOT' ">XAJavaInterop1 - llvm-ir + trimmable + llvm-ir true true 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 8c78fcdd32c..01d87d07845 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 @@ -17,7 +17,7 @@ namespace Xamarin.Android.Build.Tests { public class TrimmableTypeMapBuildTests : BaseTest { [Test] - public void Build_WithTrimmableTypeMap_Succeeds ([Values] bool isRelease, [Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime) + public void Build_WithDefaultTrimmableTypeMap_Succeeds ([Values] bool isRelease, [Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime) { if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) { return; @@ -27,7 +27,6 @@ public void Build_WithTrimmableTypeMap_Succeeds ([Values] bool isRelease, [Value IsRelease = isRelease, }; proj.SetRuntime (runtime); - proj.SetProperty ("AndroidTypeMapImplementation", "trimmable"); using var builder = CreateApkBuilder (); Assert.IsTrue (builder.Build (proj), "Build should have succeeded."); @@ -36,6 +35,34 @@ public void Build_WithTrimmableTypeMap_Succeeds ([Values] bool isRelease, [Value AssertTrimmableTypeMapOutputs (intermediateDir); } + [Test] + public void Build_WithPublishAotInDebug_UsesCoreClrAndTrimmableTypeMap () + { + if (IgnoreUnsupportedConfiguration (AndroidRuntime.CoreCLR, release: false)) { + return; + } + + var proj = new XamarinAndroidApplicationProject { + IsRelease = false, + }; + proj.SetProperty ("PublishAot", "true"); + + using var builder = CreateApkBuilder (); + Assert.IsTrue (builder.Build (proj), "Build should have succeeded."); + + var intermediateDir = builder.Output.GetIntermediaryPath ("typemap"); + AssertTrimmableTypeMapOutputs (intermediateDir); + + var environmentFiles = EnvironmentHelper.GatherEnvironmentFiles ( + builder.Output.GetIntermediaryPath (""), + "arm64-v8a", + required: true, + runtime: AndroidRuntime.CoreCLR); + Assert.IsInstanceOf ( + EnvironmentHelper.ReadApplicationConfig (environmentFiles, AndroidRuntime.CoreCLR), + "PublishAot=true in Debug should use CoreCLR."); + } + [Test] public void Build_WithTrimmableTypeMap_IncrementalBuild ([Values] bool isRelease, [Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime) { From 2171b11296b2817cd504b9ce84c09129e0cbcae0 Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Tue, 18 Aug 2026 16:40:36 +0200 Subject: [PATCH 2/5] [build] Default to trimmable typemaps for PublishAot Remove the broader runtime-selection changes and make PublishAot alone select the trimmable typemap implementation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ecfa1706-25e7-415f-a03e-af27f65164fc --- .../building-apps/build-properties.md | 9 +++--- ...oft.Android.Sdk.AssemblyResolution.targets | 1 - ...soft.Android.Sdk.DefaultProperties.targets | 6 ++-- .../TrimmableTypeMapBuildTests.cs | 31 ++----------------- 4 files changed, 8 insertions(+), 39 deletions(-) diff --git a/Documentation/docs-mobile/building-apps/build-properties.md b/Documentation/docs-mobile/building-apps/build-properties.md index ddf4d2d9bbc..31334e5ec7e 100644 --- a/Documentation/docs-mobile/building-apps/build-properties.md +++ b/Documentation/docs-mobile/building-apps/build-properties.md @@ -1248,8 +1248,8 @@ This property is obsolete and should not be used. An enum-style property that selects the type map implementation. Valid values are `llvm-ir` and `trimmable`. -The default value is `trimmable` when using CoreCLR or NativeAOT and `llvm-ir` -when using MonoVM. +The default value is `llvm-ir` when using CoreCLR and `trimmable` when using +NativeAOT. ## AndroidUseApkSigner @@ -1894,9 +1894,8 @@ Xamarin.Android. This is the same property used for [Blazor WASM][blazor]. A boolean property that controls whether Android applications use the Mono runtime instead of CoreCLR. Set this property to `true` to use -Mono or `false` to use CoreCLR. `$(PublishAot)` takes precedence. Debug -builds continue to use CoreCLR, while Release builds and publish operations -use NativeAOT. +Mono or `false` to use CoreCLR. `$(PublishAot)` takes precedence and +selects NativeAOT when set to `true`. This property defaults to `true` in .NET 10 and earlier, so Android applications use Mono. In .NET 11 and later, it defaults to `false`, diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets index beda49200da..2b056f02870 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets @@ -153,7 +153,6 @@ _ResolveAssemblies MSBuild target. ;DesignTimeBuild=$(DesignTimeBuild) ;AppendRuntimeIdentifierToOutputPath=true ;ResolveAssemblyReferencesFindRelatedSatellites=false - ;NativeCompilationDuringPublish=$(NativeCompilationDuringPublish) ;SkipCompilerExecution=true ;_OuterIntermediateAssembly=@(IntermediateAssembly) ;_OuterIntermediateSatelliteAssembliesWithTargetPath=@(IntermediateSatelliteAssembliesWithTargetPath) 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 33323b21ba2..f03550603d9 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 @@ -29,11 +29,10 @@ See: https://github.com/dotnet/sdk/blob/955c0fc7b06e2fa34bacd076ed39f61e4fb61716/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets#L16 --> <_GetChildProjectCopyToPublishDirectoryItems>false - <_AndroidRuntime Condition=" '$(PublishAot)' == 'true' and ('$(Configuration)' == 'Release' or '$(_IsPublishing)' == 'true') ">NativeAOT + <_AndroidRuntime Condition=" '$(PublishAot)' == 'true' ">NativeAOT <_AndroidRuntime Condition=" '$(PublishAot)' != 'true' and '$(UseMonoRuntime)' == 'true' ">MonoVM <_AndroidRuntime Condition=" '$(_AndroidRuntime)' == '' ">CoreCLR true - false $(AndroidMinimumSupportedApiLevel) @@ -45,8 +44,7 @@ class-parse XAJavaInterop1 <_AndroidJcwCodegenTarget Condition=" '$(_AndroidJcwCodegenTarget)' == '' and '$(_AndroidRuntime)' != 'NativeAOT' ">XAJavaInterop1 - trimmable - llvm-ir + trimmable true true 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 01d87d07845..8c78fcdd32c 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 @@ -17,7 +17,7 @@ namespace Xamarin.Android.Build.Tests { public class TrimmableTypeMapBuildTests : BaseTest { [Test] - public void Build_WithDefaultTrimmableTypeMap_Succeeds ([Values] bool isRelease, [Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime) + public void Build_WithTrimmableTypeMap_Succeeds ([Values] bool isRelease, [Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime) { if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) { return; @@ -27,6 +27,7 @@ public void Build_WithDefaultTrimmableTypeMap_Succeeds ([Values] bool isRelease, IsRelease = isRelease, }; proj.SetRuntime (runtime); + proj.SetProperty ("AndroidTypeMapImplementation", "trimmable"); using var builder = CreateApkBuilder (); Assert.IsTrue (builder.Build (proj), "Build should have succeeded."); @@ -35,34 +36,6 @@ public void Build_WithDefaultTrimmableTypeMap_Succeeds ([Values] bool isRelease, AssertTrimmableTypeMapOutputs (intermediateDir); } - [Test] - public void Build_WithPublishAotInDebug_UsesCoreClrAndTrimmableTypeMap () - { - if (IgnoreUnsupportedConfiguration (AndroidRuntime.CoreCLR, release: false)) { - return; - } - - var proj = new XamarinAndroidApplicationProject { - IsRelease = false, - }; - proj.SetProperty ("PublishAot", "true"); - - using var builder = CreateApkBuilder (); - Assert.IsTrue (builder.Build (proj), "Build should have succeeded."); - - var intermediateDir = builder.Output.GetIntermediaryPath ("typemap"); - AssertTrimmableTypeMapOutputs (intermediateDir); - - var environmentFiles = EnvironmentHelper.GatherEnvironmentFiles ( - builder.Output.GetIntermediaryPath (""), - "arm64-v8a", - required: true, - runtime: AndroidRuntime.CoreCLR); - Assert.IsInstanceOf ( - EnvironmentHelper.ReadApplicationConfig (environmentFiles, AndroidRuntime.CoreCLR), - "PublishAot=true in Debug should use CoreCLR."); - } - [Test] public void Build_WithTrimmableTypeMap_IncrementalBuild ([Values] bool isRelease, [Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime) { From c702db38d3bc16f3e5f3a4ede81dca9de33cf5b7 Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Tue, 18 Aug 2026 16:56:21 +0200 Subject: [PATCH 3/5] [docs] Document PublishAot typemap default Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ecfa1706-25e7-415f-a03e-af27f65164fc --- Documentation/docs-mobile/building-apps/build-properties.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/docs-mobile/building-apps/build-properties.md b/Documentation/docs-mobile/building-apps/build-properties.md index 31334e5ec7e..6846de0c79d 100644 --- a/Documentation/docs-mobile/building-apps/build-properties.md +++ b/Documentation/docs-mobile/building-apps/build-properties.md @@ -1248,8 +1248,8 @@ This property is obsolete and should not be used. An enum-style property that selects the type map implementation. Valid values are `llvm-ir` and `trimmable`. -The default value is `llvm-ir` when using CoreCLR and `trimmable` when using -NativeAOT. +The default value is `trimmable` when `$(PublishAot)` is `true` and `llvm-ir` +otherwise. ## AndroidUseApkSigner From 8870407a643cf570d0159a4b129886d3286da35e Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Wed, 19 Aug 2026 11:42:39 +0200 Subject: [PATCH 4/5] [build] Test PublishAot CoreCLR Debug typemaps Keep NativeCompilationDuringPublish disabled for CoreCLR inner-loop builds and cover the PublishAot Debug trimmable typemap path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ce335541-30db-4fd1-8799-24078022b70c --- .../Microsoft.Android.Sdk.CoreCLR.targets | 2 ++ .../TrimmableTypeMapBuildTests.cs | 20 +++++++++++++++++++ 2 files changed, 22 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 ae749f1cf2c..060dccd8a78 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 @@ -12,6 +12,8 @@ This file contains the CoreCLR-specific MSBuild logic for .NET for Android. <_AndroidRuntimePackRuntime>CoreCLR + + false 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 8c78fcdd32c..3ed6b28c2ed 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 5dccaad1c2c7fdabe8476cada35cab321ee3839d Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Wed, 19 Aug 2026 11:54:07 +0200 Subject: [PATCH 5/5] [tests] Isolate PublishAot typemap coverage Remove the unrelated CoreCLR NativeCompilationDuringPublish default and set it only in the regression test so the test covers typemap selection without invoking ILC. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ce335541-30db-4fd1-8799-24078022b70c --- .../targets/Microsoft.Android.Sdk.CoreCLR.targets | 2 -- .../Xamarin.Android.Build.Tests/TrimmableTypeMapBuildTests.cs | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) 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 060dccd8a78..ae749f1cf2c 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 @@ -12,8 +12,6 @@ This file contains the CoreCLR-specific MSBuild logic for .NET for Android. <_AndroidRuntimePackRuntime>CoreCLR - - false 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 3ed6b28c2ed..769a2e4992b 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 @@ -48,6 +48,7 @@ public void Build_PublishAotProject_UsesTrimmableTypeMapForCoreClrDebug () }; proj.SetRuntime (AndroidRuntime.CoreCLR); proj.SetProperty (KnownProperties.PublishAot, "true"); + proj.SetProperty ("NativeCompilationDuringPublish", "false"); using var builder = CreateApkBuilder (); Assert.IsTrue (builder.Build (proj, parameters: [ "_AndroidRuntime=CoreCLR" ]), "Build should have succeeded.");