Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\MonoDroid.Tuner\AndroidLinkConfiguration.cs" Link="MonoDroid.Tuner\AndroidLinkConfiguration.cs" />
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\MonoDroid.Tuner\Extensions.cs" Link="MonoDroid.Tuner\Extensions.cs" />
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\MonoDroid.Tuner\FixAbstractMethodsStep.cs" Link="MonoDroid.Tuner\FixAbstractMethodsStep.cs" />
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\MonoDroid.Tuner\FixLegacyResourceDesignerStep.cs" Link="MonoDroid.Tuner\FixLegacyResourceDesignerStep.cs" />
<Compile Include="..\Xamarin.Android.Build.Tasks\Linker\MonoDroid.Tuner\LinkDesignerBase.cs" Link="MonoDroid.Tuner\LinkDesignerBase.cs" />

<!--Other .NET for Android / Java.Interop files-->
<Compile Include="..\..\external\Java.Interop\src\Java.Interop.Tools.Cecil\Java.Interop.Tools.Cecil\CustomAttributeProviderRocks.cs" Link="Java.Interop\CustomAttributeProviderRocks.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ public virtual void LogMessage (string message)

public virtual void LogError (int code, string message)
{
#if ILLINK
Context.LogMessage (MessageContainer.CreateCustomErrorMessage (message, code, origin: new MessageOrigin ()));
#else // !ILLINK
Context.LogError ($"XA{code}", message);
#endif // !ILLINK
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,11 @@
using Mono.Linker.Steps;

using Mono.Tuner;
#if ILLINK
using Resources = Microsoft.Android.Sdk.ILLink.Properties.Resources;
#else // !ILLINK
using Resources = Xamarin.Android.Tasks.Properties.Resources;
#endif // ILLINK

namespace MonoDroid.Tuner
{
public class FixLegacyResourceDesignerStep : LinkDesignerBase
#if !ILLINK
, Xamarin.Android.Tasks.IAssemblyModifierPipelineStep
#endif // !ILLINK
public class FixLegacyResourceDesignerStep : LinkDesignerBase, Xamarin.Android.Tasks.IAssemblyModifierPipelineStep
{
internal const string DesignerAssemblyName = "_Microsoft.Android.Resource.Designer";
internal const string DesignerAssemblyNamespace = "_Microsoft.Android.Resource.Designer";
Expand All @@ -36,14 +29,6 @@ public class FixLegacyResourceDesignerStep : LinkDesignerBase
Dictionary<string, MethodDefinition> lookup;
Dictionary<string, MethodDefinition> lookupCaseInsensitive;

protected override void EndProcess ()
{
if (designerAssembly != null) {
LogMessage ($" Setting Action on {designerAssembly.Name} to Link.");
Annotations.SetAction (designerAssembly, AssemblyAction.Link);
}
}

protected override void LoadDesigner ()
{
if (designerLoaded)
Expand Down Expand Up @@ -72,7 +57,6 @@ protected override void LoadDesigner ()
}
}

#if !ILLINK
public void ProcessAssembly (AssemblyDefinition assembly, Xamarin.Android.Tasks.StepContext context)
{
// Only run this step on non-main user Android assemblies
Expand All @@ -81,7 +65,6 @@ public void ProcessAssembly (AssemblyDefinition assembly, Xamarin.Android.Tasks.

context.IsAssemblyModified |= ProcessAssemblyDesigner (assembly);
}
#endif // !ILLINK

internal override bool ProcessAssemblyDesigner (AssemblyDefinition assembly)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,27 @@
using Mono.Linker;
using Mono.Linker.Steps;
using System;
using System.Linq;
using Xamarin.Android.Tasks;
using System.Collections.Generic;
using System.Globalization;
using Mono.Cecil.Cil;
using System.Text.RegularExpressions;
using Mono.Collections.Generic;
#if ILLINK
using Microsoft.Android.Sdk.ILLink;
#endif


namespace MonoDroid.Tuner {
public abstract class LinkDesignerBase : BaseStep
{
protected IMetadataResolver Cache => Context;

public
#if !ILLINK
override
#endif
void LogMessage (string message)
public override void LogMessage (string message)
{
Context.LogMessage (message);
}

public
#if !ILLINK
override
#endif
void LogError (int code, string error)
public override void LogError (int code, string error)
{
#if ILLINK
Context.LogMessage (MessageContainer.CreateCustomErrorMessage (error, code, origin: new MessageOrigin ()));
#else // !ILLINK
Context.LogError ($"XA{code}", error);
#endif // !ILLINK
}

public virtual AssemblyDefinition Resolve (AssemblyNameReference name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,6 @@
<_TrimmerCustomSteps Include="$(_AndroidLinkerCustomStepAssembly)" Type="MonoDroid.Tuner.FixAbstractMethodsStep" />
<!-- Custom steps that run after MarkStep -->
<!-- Custom steps that run after CleanStep -->
<_TrimmerCustomSteps
Condition=" '$(AndroidUseDesignerAssembly)' == 'true' "
Include="$(_AndroidLinkerCustomStepAssembly)"
BeforeStep="MarkStep"
Type="MonoDroid.Tuner.FixLegacyResourceDesignerStep"
/>
<_TrimmerCustomSteps
Condition=" '$(_AndroidTypeMapImplementation)' == 'managed' "
Include="$(_AndroidLinkerCustomStepAssembly)"
Expand Down Expand Up @@ -248,7 +242,8 @@
Assemblies="@(_PostTrimmingAssembly)"
AddKeepAlives="$(AndroidAddKeepAlives)"
AndroidLinkResources="$(AndroidLinkResources)"
Deterministic="$(Deterministic)" />
Deterministic="$(Deterministic)"
UseDesignerAssembly="$(AndroidUseDesignerAssembly)" />
</Target>

<!-- Inject _TypeMapKind into the property cache -->
Expand Down
33 changes: 33 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Tasks/PostTrimmingPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Android.Build.Tasks;
using Microsoft.Build.Framework;
using Mono.Cecil;
using Mono.Linker;
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using Mono.Linker; appears to be unused in this file (the only Mono.Linker types used are referenced indirectly via MSBuildLinkContext, which is in Xamarin.Android.Tasks). With analyzers enabled, this can surface as IDE0005; consider removing the unused using to keep the file warning-clean.

Suggested change
using Mono.Linker;

Copilot uses AI. Check for mistakes.
using MonoDroid.Tuner;

namespace Xamarin.Android.Tasks;
Expand Down Expand Up @@ -34,6 +35,8 @@ public class PostTrimmingPipeline : AndroidTask

public bool Deterministic { get; set; }

public bool UseDesignerAssembly { get; set; }

public override bool RunTask ()
{
using var resolver = new DirectoryAssemblyResolver (
Expand Down Expand Up @@ -70,6 +73,15 @@ public override bool RunTask ()
},
(msg) => Log.LogDebugMessage (msg)));
}
if (UseDesignerAssembly) {
// Create an MSBuildLinkContext so FixLegacyResourceDesignerStep can resolve assemblies
// and log messages. The resolver is owned by the outer 'using' block, so we intentionally
// do not dispose this context (LinkContext.Dispose would double-dispose the resolver).
var linkContext = new MSBuildLinkContext (resolver, Log);
var fixLegacyStep = new FixLegacyResourceDesignerStep ();
fixLegacyStep.Initialize (linkContext);
steps.Add (new PostTrimmingFixLegacyResourceDesignerStep (fixLegacyStep));
}
Comment on lines +76 to +84
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new UseDesignerAssembly post-trim path adds a non-trivial behavioral change (running FixLegacyResourceDesignerStep after ILLink). There don’t appear to be existing tests that specifically exercise PublishTrimmed=true + AndroidUseDesignerAssembly=true and assert the legacy designer fix still happens. Adding an integration test that builds/publishes trimmed and validates resource designer accesses are rewritten (and no XA8000/XA1034 regressions) would help prevent future regressions.

Copilot uses AI. Check for mistakes.
if (AndroidLinkResources) {
var allAssemblies = new List<AssemblyDefinition> (Assemblies.Length);
foreach (var item in Assemblies) {
Expand All @@ -96,3 +108,24 @@ public override bool RunTask ()
return !Log.HasLoggedErrors;
}
}

/// <summary>
/// Thin wrapper around <see cref="FixLegacyResourceDesignerStep"/> for the post-trimming pipeline.
/// Calls <see cref="FixLegacyResourceDesignerStep.ProcessAssemblyDesigner"/> directly, matching the
/// behavior of the former ILLink path which processed all assemblies without StepContext flag filtering.
/// Assemblies without a resource designer are skipped internally by ProcessAssemblyDesigner.
/// </summary>
class PostTrimmingFixLegacyResourceDesignerStep : IAssemblyModifierPipelineStep
{
readonly FixLegacyResourceDesignerStep _inner;

public PostTrimmingFixLegacyResourceDesignerStep (FixLegacyResourceDesignerStep inner)
{
_inner = inner;
}

public void ProcessAssembly (AssemblyDefinition assembly, StepContext context)
{
context.IsAssemblyModified |= _inner.ProcessAssemblyDesigner (assembly);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<Compile Include="..\..\bin\Build$(Configuration)\XABuildConfig.cs" />

<!-- Include only the linker sources required for the build tasks (LinkAssembliesNoShrink and PostTrimmingPipeline) -->
<!-- These include: AddKeepAlivesStep, AddKeepAlivesHelper, CheckForObsoletePreserveAttributeStep, StripEmbeddedLibrariesStep, PostTrimmingAddKeepAlivesStep, FixAbstractMethodsStep, FixLegacyResourceDesignerStep -->
<!-- These include: AddKeepAlivesStep, AddKeepAlivesHelper, CheckForObsoletePreserveAttributeStep, StripEmbeddedLibrariesStep, PostTrimmingAddKeepAlivesStep, FixAbstractMethodsStep, FixLegacyResourceDesignerStep, LinkDesignerBase -->
<Compile Remove="Linker\**" />
<Compile Include="Linker\MonoDroid.Tuner\FindTypeMapObjectsStep.cs" />
<Compile Include="Linker\MonoDroid.Tuner\FindJavaObjectsStep.cs" />
Expand Down
Loading