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
@@ -1,36 +1,38 @@
using Mono.Cecil;
using Mono.Linker;
using Mono.Linker.Steps;
using System;
using System.Linq;
using Microsoft.Android.Build.Tasks;
using Microsoft.Build.Utilities;
using Mono.Cecil;
using Xamarin.Android.Tasks;

namespace MonoDroid.Tuner
{
public class StripEmbeddedLibraries : BaseStep
public class StripEmbeddedLibrariesStep : IAssemblyModifierPipelineStep
{
protected override void ProcessAssembly (AssemblyDefinition assembly)
public TaskLoggingHelper Log { get; }

public StripEmbeddedLibrariesStep (TaskLoggingHelper log)
{
if (!Annotations.HasAction (assembly))
return;
var action = Annotations.GetAction (assembly);
if (action == AssemblyAction.Skip || action == AssemblyAction.Delete)
return;
Log = log;
}

if (MonoAndroidHelper.IsFrameworkAssembly (assembly))
public void ProcessAssembly (AssemblyDefinition assembly, StepContext context)
{
if (context.IsFrameworkAssembly)
return;

bool assembly_modified = false;
foreach (var mod in assembly.Modules) {
foreach (var r in mod.Resources.ToArray ()) {
if (ShouldStripResource (r)) {
Context.LogMessage ($" Stripped {r.Name} from {assembly.Name.Name}.dll");
Log.LogDebugMessage ($" Stripped {r.Name} from {assembly.Name.Name}.dll");
mod.Resources.Remove (r);
assembly_modified = true;
}
}
}
if (assembly_modified && action == AssemblyAction.Copy) {
Annotations.SetAction (assembly, AssemblyAction.Save);
if (assembly_modified) {
context.IsAssemblyModified = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ This file contains the .NET 5-specific targets to customize ILLink
Type="MonoDroid.Tuner.AddKeepAlivesStep"
/>
<!-- Custom steps that run after CleanStep -->
<_TrimmerCustomSteps Include="$(_AndroidLinkerCustomStepAssembly)" AfterStep="CleanStep" Type="MonoDroid.Tuner.StripEmbeddedLibraries" />
<_TrimmerCustomSteps
Condition=" '$(AndroidLinkResources)' == 'true' "
Include="$(_AndroidLinkerCustomStepAssembly)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ protected virtual void BuildPipeline (AssemblyPipeline pipeline, MSBuildLinkCont
findJavaObjectsStep.Initialize (context);
pipeline.Steps.Add (findJavaObjectsStep);

// StripEmbeddedLibrariesStep
var stripEmbeddedLibrariesStep = new StripEmbeddedLibrariesStep (Log);
pipeline.Steps.Add (stripEmbeddedLibrariesStep);

// SaveChangedAssemblyStep
var writerParameters = new WriterParameters {
DeterministicMvid = Deterministic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Compile Include="Linker\MonoDroid.Tuner\FixLegacyResourceDesignerStep.cs" />
<Compile Include="Linker\MonoDroid.Tuner\LinkDesignerBase.cs" />
<Compile Include="Linker\MonoDroid.Tuner\RemoveResourceDesignerStep.cs" />
<Compile Include="Linker\MonoDroid.Tuner\StripEmbeddedLibrariesStep.cs" />
<Compile Include="Linker\External\Linker\Annotations.cs" />
<Compile Include="Linker\External\Linker\AssemblyAction.cs" />
<Compile Include="Linker\External\Linker\AssemblyResolver.cs" />
Expand Down