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 14eb57c1134..a356e2fe0a6 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 @@ -47,7 +47,7 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android. - + _AndroidBeforeIlcCompile; SetupOSSpecificProps; @@ -57,10 +57,22 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android. _AndroidComputeIlcCompileInputs; $(IlcCompileDependsOn) + <_AndroidBeforeIlcCompileDependsOn>_PrepareLinking + + + + + _AndroidBeforeIlcCompile; + SetupOSSpecificProps; + ComputeIlcCompileInputs; + _AndroidComputeIlcCompileInputs; + $(IlcCompileDependsOn) + + <_AndroidBeforeIlcCompileDependsOn>_CreatePropertiesCache @@ -110,7 +122,10 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android. false + + + true $(_OriginalSuppressTrimAnalysisWarnings) @@ -137,26 +152,27 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android. - - <_IlcManagedInputAssemblies Remove="@(_IlcManagedInputAssemblies)" /> - - - - - <_AndroidILLinkAssemblies Include="@(ManagedAssemblyToLink->'$(IntermediateLinkDir)%(Filename)%(Extension)')" Condition="Exists('$(IntermediateLinkDir)%(Filename)%(Extension)')" /> - + + + <_IlcManagedInputAssemblies Remove="@(_IlcManagedInputAssemblies)" /> + + + + + - - + <_AndroidILLinkAssemblies Include="@(ManagedAssemblyToLink->'$(IntermediateLinkDir)%(Filename)%(Extension)')" Condition="Exists('$(IntermediateLinkDir)%(Filename)%(Extension)')" /> - - + + + @@ -265,9 +281,13 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android. Restore the old scheduling so NativeCompile runs after ComputeResolvedFilesToPublishList in the inner per-RID build. --> + + <_AndroidRunNativeCompileDependsOn Condition=" '$(_AndroidTypeMapImplementation)' != 'trimmable' ">_PreTrimmingFixLegacyDesignerUpdateItems;NativeCompile + <_AndroidRunNativeCompileDependsOn Condition=" '$(_AndroidTypeMapImplementation)' == 'trimmable' ">NativeCompile + + DependsOnTargets="$(_AndroidRunNativeCompileDependsOn)" /> 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 15938fd1439..fcd91087799 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 @@ -9,10 +9,21 @@ namespace Xamarin.Android.Build.Tests { public class TrimmableTypeMapBuildTests : BaseTest { [Test] - public void Build_WithTrimmableTypeMap_Succeeds () + public void Build_WithTrimmableTypeMap_Succeeds ([Values] bool isRelease, [Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime) { - var proj = new XamarinAndroidApplicationProject (); - proj.SetRuntime (AndroidRuntime.CoreCLR); + if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) { + return; + } + + if (runtime == AndroidRuntime.CoreCLR && isRelease) { + Assert.Ignore ("CoreCLR + Release trimmable typemap not yet supported"); + return; + } + + var proj = new XamarinAndroidApplicationProject { + IsRelease = isRelease, + }; + proj.SetRuntime (runtime); proj.SetProperty ("_AndroidTypeMapImplementation", "trimmable"); // Full Build will fail downstream (manifest generation not yet implemented for trimmable path), @@ -27,10 +38,27 @@ public void Build_WithTrimmableTypeMap_Succeeds () } [Test] - public void Build_WithTrimmableTypeMap_IncrementalBuild () + public void Build_WithTrimmableTypeMap_IncrementalBuild ([Values] bool isRelease, [Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime) { - var proj = new XamarinAndroidApplicationProject (); - proj.SetRuntime (AndroidRuntime.CoreCLR); + if (IgnoreUnsupportedConfiguration (runtime, release: isRelease)) { + return; + } + + if (runtime == AndroidRuntime.CoreCLR && isRelease) { + Assert.Ignore ("CoreCLR + Release trimmable typemap not yet supported"); + return; + } + + // https://github.com/dotnet/android/issues/11210 + if (runtime == AndroidRuntime.NativeAOT) { + Assert.Ignore ("NativeAOT trimmable build does not yet generate JavaInteropRuntime.java"); + return; + } + + var proj = new XamarinAndroidApplicationProject { + IsRelease = isRelease, + }; + proj.SetRuntime (runtime); proj.SetProperty ("_AndroidTypeMapImplementation", "trimmable"); // Full Build will fail downstream (manifest generation not yet implemented for trimmable path),