-
Notifications
You must be signed in to change notification settings - Fork 566
Expand file tree
/
Copy pathStripEmbeddedLibrariesStep.cs
More file actions
58 lines (53 loc) · 1.48 KB
/
StripEmbeddedLibrariesStep.cs
File metadata and controls
58 lines (53 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Microsoft.Android.Build.Tasks;
using Microsoft.Build.Utilities;
using Mono.Cecil;
using System;
using System.Linq;
using Xamarin.Android.Tasks;
namespace MonoDroid.Tuner
{
public class StripEmbeddedLibrariesStep : IAssemblyModifierPipelineStep
{
public TaskLoggingHelper Log { get; }
public StripEmbeddedLibrariesStep (TaskLoggingHelper log)
{
Log = log;
}
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)) {
Log.LogDebugMessage ($" Stripped {r.Name} from {assembly.Name.Name}.dll");
mod.Resources.Remove (r);
assembly_modified = true;
}
}
}
if (assembly_modified) {
context.IsAssemblyModified = true;
}
}
bool ShouldStripResource (Resource r)
{
if (!(r is EmbeddedResource))
return false;
// embedded jars
if (r.Name.EndsWith (".jar", StringComparison.InvariantCultureIgnoreCase))
return true;
// embedded AndroidNativeLibrary archive
if (r.Name == "__AndroidNativeLibraries__.zip")
return true;
// embedded AndroidResourceLibrary archive
if (r.Name == "__AndroidLibraryProjects__.zip")
return true;
// embedded AndroidEnvironment item
if (r.Name.StartsWith ("__AndroidEnvironment__", StringComparison.Ordinal))
return true;
return false;
}
}
}