diff --git a/Documentation/docs-mobile/building-apps/build-properties.md b/Documentation/docs-mobile/building-apps/build-properties.md index bbed1718b21..11d6036471b 100644 --- a/Documentation/docs-mobile/building-apps/build-properties.md +++ b/Documentation/docs-mobile/building-apps/build-properties.md @@ -1869,6 +1869,11 @@ For Android applications that use CoreCLR, this property defaults to `Debug` configuration. ReadyToRun does not apply when using Mono or NativeAOT. +ReadyToRun requires trimming. If `$(PublishTrimmed)` is not `true`, +.NET for Android disables `PublishReadyToRun` and +[`$(PublishReadyToRunComposite)`](#publishreadytoruncomposite) and emits +warning XA0119. + ReadyToRun compilation is composite by default. See [`$(PublishReadyToRunComposite)`](#publishreadytoruncomposite). .NET MAUI also uses partial ReadyToRun with default MIBC profiles. See @@ -1889,6 +1894,8 @@ time. For Android applications that use CoreCLR, this property defaults to `true` when [`$(PublishReadyToRun)`](#publishreadytorun) is `true`. +ReadyToRun, including composite ReadyToRun, requires +`$(PublishTrimmed)` to be `true`. ## RunAOTCompilation diff --git a/Documentation/docs-mobile/messages/xa0119.md b/Documentation/docs-mobile/messages/xa0119.md index 17a00ac6594..5709cc48ea2 100644 --- a/Documentation/docs-mobile/messages/xa0119.md +++ b/Documentation/docs-mobile/messages/xa0119.md @@ -45,7 +45,7 @@ Remove the following from `Release` configurations: * `False` * `True` or in .NET 6 `True` -* `True` (for CoreCLR) +* `True` (for CoreCLR, when trimming is enabled) Consider submitting a [bug][bug] if you are getting one of these warnings under normal circumstances. 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..9d687057a26 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 @@ -17,6 +17,9 @@ This file contains the CoreCLR-specific MSBuild logic for .NET for Android. true + <_AndroidReadyToRunWithoutTrimming Condition=" '$(PublishReadyToRun)' == 'true' and '$(PublishTrimmed)' != 'true' ">true + false + false true <_IsPublishing Condition=" '$(_IsPublishing)' == '' and '$(PublishReadyToRun)' == 'true' ">true true diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index ebf1bb55b0f..5b0e5b1999e 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -317,6 +317,10 @@ The term "lock file" comes from NuGet. For example, search for "UnauthorizedLock Using fast deployment and ReadyToRun at the same time is not recommended. Use fast deployment for Debug configurations and ReadyToRun for Release configurations. The following are literal names and should not be translated: ReadyToRun, Debug, Release. + + ReadyToRun has been disabled because trimming is disabled. Set the 'PublishTrimmed' MSBuild property to 'true' to use ReadyToRun. + The following are literal names and should not be translated: ReadyToRun, 'PublishTrimmed', 'true'. + Assembly '{0}' is using '[assembly: {1}]', which is no longer supported. Use a newer version of this NuGet package or notify the library author. The following are literal names and should not be translated: [assembly: {1}], NuGet diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs index 63a575f42a2..b0340332d29 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs @@ -2306,21 +2306,6 @@ public void CheckLintResourceFileReferencesAreFixed ([Values (AndroidRuntime.Cor // TODO: [TestCase (false, AndroidRuntime.NativeAOT)] public void SimilarAndroidXAssemblyNames (bool publishTrimmed, AndroidRuntime runtime) { - if (!publishTrimmed && runtime == AndroidRuntime.CoreCLR) { - // This currently fails with the following exception: - // - // error XALNS7015: System.NotSupportedException: Writing mixed-mode assemblies is not supported - // at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters) - // at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters) - // at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters) - // at Mono.Cecil.AssemblyDefinition.Write(String fileName, WriterParameters parameters) - // at Xamarin.Android.Tasks.SaveChangedAssemblyStep.ProcessAssembly(AssemblyDefinition assembly, StepContext context) in src/Xamarin.Android.Build.Tasks/Tasks/AssemblyModifierPipeline.cs:line 197 - // at Xamarin.Android.Tasks.AssemblyPipeline.Run(AssemblyDefinition assembly, StepContext context) in src/Xamarin.Android.Build.Tasks/Utilities/AssemblyPipeline.cs:line 26 - // at Xamarin.Android.Tasks.AssemblyModifierPipeline.RunPipeline(AssemblyPipeline pipeline, ITaskItem source, ITaskItem destination) in src/Xamarin.Android.Build.Tasks/Tasks/AssemblyModifierPipeline.cs:line 175 - Assert.Ignore ("CoreCLR: fails because of a Mono.Cecil lack of support"); - return; - } - bool aotAssemblies = runtime == AndroidRuntime.MonoVM && publishTrimmed; var proj = new XamarinAndroidApplicationProject { IsRelease = true, @@ -2337,6 +2322,24 @@ public void SimilarAndroidXAssemblyNames (bool publishTrimmed, AndroidRuntime ru Assert.IsTrue (builder.Build (proj), "Build should have succeeded."); } + [Test] + public void FixAbstractMethodsOnReadyToRunAssembly () + { + var proj = new XamarinAndroidApplicationProject { + IsRelease = true, + PackageReferences = { + new Package { Id = "Xamarin.AndroidX.CustomView", Version = "1.1.0.17" }, + new Package { Id = "Xamarin.AndroidX.CustomView.PoolingContainer", Version = "1.0.0.4" }, + } + }; + proj.SetRuntime (AndroidRuntime.CoreCLR); + proj.SetProperty (KnownProperties.PublishTrimmed, false.ToString ()); + proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", "AndroidX.CustomView.PoolingContainer.PoolingContainer.IsPoolingContainer (null);"); + using var builder = CreateApkBuilder (); + Assert.IsTrue (builder.Build (proj), "Build should have succeeded."); + StringAssertEx.Contains ("warning XA0119: ReadyToRun has been disabled because trimming is disabled.", builder.LastBuildOutput); + } + [Test] public void IncrementalBuildDifferentDevice ([Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime) { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs index 48cd2eb9d58..0ceae4e9336 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs @@ -115,6 +115,7 @@ public void BasicApplicationPublishReadyToRunCustomConfiguration ([Values] bool proj.SetProperty ("AndroidEnableAssemblyCompression", "false"); proj.SetProperty ("Optimize", "true"); proj.SetProperty ("DebugType", "None"); + proj.SetProperty ("PublishTrimmed", "true"); proj.SetProperty ("PublishReadyToRunComposite", isComposite.ToString ()); // Use `dotnet publish` rather than `msbuild /t:Publish`: only the `dotnet publish` CLI diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 57fa1a57afc..71fc58ccc8a 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -528,6 +528,10 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. ResourceName="XA0119_ReadyToRun" Condition=" '$(AndroidEnableFastDeployment)' == 'True' And '$(PublishReadyToRun)' == 'True' " /> +