Skip to content

Commit 712be22

Browse files
committed
[Xamarin.Android.Build.Tasks] Dispose DirectoryAssemblyResolver instances
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=44529 Commit 1d65825 bumped to Cecil 0.10.0-beta1-v2 and Java.Interop/a1d3ecc8, which likewise uses Cecil 0.10.0-beta1-v2. Among the various API changes in Cecil 0.10.x vs. Cecil 0.9.x is a change to `Mono.Cecil.IAssemblyResolver`, implemented by `Java.Interop.Tools.Cecil.DirectoryAssemblyResolver`, to implement the `IDisposable` interface. Java.Interop/a1d3ecc8 added a `DirectoryAssemblyResolver.Dispose()` method, but this method didn't *do* anything. Cecil 0.10.0-beta1-v2 also has a *semantic* change vs. Cecil 0.9.x: `AssemblyDefinition` is no longer a "purely in-memory" construct. Instead, it holds a `System.IO.Stream` to the assembly it's reading (unless `Mono.Cecil.ReaderParameters.InMemory` is `true`). This semantic change means that an assembly can't be read from and written to at the same time via different mechanisms, so long as there is an `AssemblyDefinition` instance to that file. Which brings us to (private) Bug #44529, in which an `IOException` is thrown from the `<StripEmbeddedLibraries/>` task: Error executing task StripEmbeddedLibraries: System.IO.IOException: Sharing violation on path .../obj/Release/linksrc/Xamarin.Android.NUnitLite.dll at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x0025f] in <253a3790b2c44512bbca8669ecfc1822>:0 at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in <253a3790b2c44512bbca8669ecfc1822>:0 at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare) at Mono.Cecil.ModuleDefinition.GetFileStream (System.String fileName, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00007] in :0 at Mono.Cecil.ModuleDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) [0x00007] in :0 at Mono.Cecil.AssemblyDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) [0x00001] in :0 at Xamarin.Android.Tasks.StripEmbeddedLibraries.Execute () [0x0034a] in <3d5202a5d4874a76a99388021bf1ab1a>:0 The underlying cause of the `IOException` is twofold: 1. `AssemblyDefinition` instances now hold a `FileStream` to the file they're reading from (and optionally writing to), and this `FileStream` will be kept open until `AssemblyDefinition.Dispose()` is called. 2. Nothing in `Xamarin.Android.Build.Tasks` calls `AssemblyDefinition.Dispose()`. Nor should anything in `Xamarin.Android.Build.Tasks` call `AssemblyDefinition.Dispose()`! (Almost) All `AssemblyDefinition` instances are *cached* within `DirectoryAssemblyResolver` instances, and nothing calls `DirectoryAssemblyResolver.Dispose()` either! (Not that this matters *too* much, becuase `DirectoryAssemblyResolver.Dispose()` is currently a no-op.) There is no sane reasoning here: so long as we're using `DirectoryAssemblyResolver`, we're going to have more files open (compared to when Cecil 0.9.x was used), which can result in file sharing problems and the above `IOException`. The way foward is: 1. `Java.Interop.Tools.Cecil.DirectoryAssemblyResolver` needs to be updated so that [`DirectoryAssemblyResolver.Dispose()` is useful][0], i.e. that it will `Dispose()` of all held `AssemblyDefinition` instances. 2. The Java.Interop subproject reference needs to be updated to pick up (1). TODO: do this. ;-) 3. `Xamarin.Android.Build.Tasks.dll` needs to be updated so that `DirectoryAssemblyResolver.Dispose()` is used. 4. All code, in particular `Xamarin.Andorid.Build.Tasks.dll`, needs to be reviewed to ensure it doesn't do anything "stupid" with `AssemblyDefinition` instances and/or `DirectoryAssemblyResolver.` Examples of "stupid" things include: * `Dispose()`ing of the return value from `DirectoryAssemblyResolver.Load()`: resolver.Load (assemblyName).Dispose(); * Treating `AssemblyDefinition` instances in a manner inconsistent with how `DirectoryAssemblyResolver` loads them. `DirectoryAssemblyResolver` will be getting a new constructor overload which takes an `Mono.Cecil.ReaderParameters` parameter; the default will be the default Cecil behavior, which is for read-only behavior. Thus, trying to use the `AssemblyDefinition` in a "write" context will fail: var r = new DirectoryAssemblyResolver (...); var a = r.Load (assemblyName); a.Write (); // BOOM [0]: dotnet/java-interop#88
1 parent 9187b4d commit 712be22

File tree

9 files changed

+120
-96
lines changed

9 files changed

+120
-96
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -444,30 +444,31 @@ void AddRuntimeLibraries (ZipArchive apk, string supportedAbis)
444444
void AddNativeLibrariesFromAssemblies (ZipArchive apk, string supportedAbis)
445445
{
446446
var abis = supportedAbis.Split (new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
447-
var res = new DirectoryAssemblyResolver (Console.WriteLine, loadDebugSymbols: false);
447+
using (var res = new DirectoryAssemblyResolver (Console.WriteLine, loadDebugSymbols: false)) {
448448
foreach (var assembly in EmbeddedNativeLibraryAssemblies)
449449
res.Load (assembly.ItemSpec);
450-
foreach (var assemblyPath in EmbeddedNativeLibraryAssemblies) {
451-
var assembly = res.GetAssembly (assemblyPath.ItemSpec);
452-
foreach (var mod in assembly.Modules) {
453-
var ressozip = mod.Resources.FirstOrDefault (r => r.Name == "__AndroidNativeLibraries__.zip") as EmbeddedResource;
454-
if (ressozip == null)
455-
continue;
456-
var data = ressozip.GetResourceData ();
457-
using (var ms = new MemoryStream (data)) {
458-
using (var zip = ZipArchive.Open (ms)) {
459-
foreach (var e in zip.Where (x => abis.Any (a => x.FullName.Contains (a)))) {
460-
if (e.IsDirectory)
461-
continue;
462-
var key = e.FullName.Replace ("native_library_imports", "lib");
463-
if (apk.Any(k => k.FullName == key)) {
464-
Log.LogCodedWarning ("4301", "Apk already contains the item {0}; ignoring.", key);
465-
continue;
466-
}
467-
using (var s = new MemoryStream ()) {
468-
e.Extract (s);
469-
s.Position = 0;
470-
apk.AddEntry (s.ToArray (),key);
450+
foreach (var assemblyPath in EmbeddedNativeLibraryAssemblies) {
451+
var assembly = res.GetAssembly (assemblyPath.ItemSpec);
452+
foreach (var mod in assembly.Modules) {
453+
var ressozip = mod.Resources.FirstOrDefault (r => r.Name == "__AndroidNativeLibraries__.zip") as EmbeddedResource;
454+
if (ressozip == null)
455+
continue;
456+
var data = ressozip.GetResourceData ();
457+
using (var ms = new MemoryStream (data)) {
458+
using (var zip = ZipArchive.Open (ms)) {
459+
foreach (var e in zip.Where (x => abis.Any (a => x.FullName.Contains (a)))) {
460+
if (e.IsDirectory)
461+
continue;
462+
var key = e.FullName.Replace ("native_library_imports", "lib");
463+
if (apk.Any (k => k.FullName == key)) {
464+
Log.LogCodedWarning ("4301", "Apk already contains the item {0}; ignoring.", key);
465+
continue;
466+
}
467+
using (var s = new MemoryStream ()) {
468+
e.Extract (s);
469+
s.Position = 0;
470+
apk.AddEntry (s.ToArray (), key);
471+
}
471472
}
472473
}
473474
}

src/Xamarin.Android.Build.Tasks/Tasks/CheckTargetFrameworks.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ public class CheckTargetFrameworks : Task
2323
public string ProjectFile { get; set; }
2424

2525
Dictionary<ITaskItem, int> apiLevels = new Dictionary<ITaskItem, int> ();
26-
DirectoryAssemblyResolver res;
2726

28-
int ExtractApiLevel(ITaskItem ass)
27+
int ExtractApiLevel(DirectoryAssemblyResolver res, ITaskItem ass)
2928
{
3029
Log.LogDebugMessage (ass.ItemSpec);
3130
foreach (var ca in res.GetAssembly (ass.ItemSpec).CustomAttributes) {
@@ -51,13 +50,14 @@ public override bool Execute ()
5150
Log.LogDebugMessage (" ProjectFile: {0}", ProjectFile);
5251
Log.LogDebugTaskItems (" ResolvedUserAssemblies: {0}", ResolvedAssemblies);
5352

54-
res = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols: false);
55-
foreach (var assembly in ResolvedAssemblies) {
56-
res.Load (Path.GetFullPath (assembly.ItemSpec));
57-
var apiLevel = ExtractApiLevel (assembly);
58-
if (apiLevel > 0) {
59-
Log.LogDebugMessage ("{0}={1}", Path.GetFileNameWithoutExtension (assembly.ItemSpec), apiLevel);
60-
apiLevels.Add (assembly, apiLevel);
53+
using (var res = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols: false)) {
54+
foreach (var assembly in ResolvedAssemblies) {
55+
res.Load (Path.GetFullPath (assembly.ItemSpec));
56+
var apiLevel = ExtractApiLevel (res, assembly);
57+
if (apiLevel > 0) {
58+
Log.LogDebugMessage ("{0}={1}", Path.GetFileNameWithoutExtension (assembly.ItemSpec), apiLevel);
59+
apiLevels.Add (assembly, apiLevel);
60+
}
6161
}
6262
}
6363

src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ public override bool Execute ()
7979
Log.LogDebugMessage (" ApplicationJavaClass: {0}", ApplicationJavaClass);
8080

8181
try {
82-
Run ();
82+
// We're going to do 3 steps here instead of separate tasks so
83+
// we can share the list of JLO TypeDefinitions between them
84+
using (var res = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols: true)) {
85+
Run (res);
86+
}
8387
}
8488
catch (XamarinAndroidException e) {
8589
Log.LogCodedError (string.Format ("XA{0:0000}", e.Code), e.MessageWithoutCode);
@@ -90,17 +94,13 @@ public override bool Execute ()
9094
return !Log.HasLoggedErrors;
9195
}
9296

93-
void Run ()
97+
void Run (DirectoryAssemblyResolver res)
9498
{
9599
PackageNamingPolicy pnp;
96100
JniType.PackageNamingPolicy = Enum.TryParse (PackageNamingPolicy, out pnp) ? pnp : PackageNamingPolicyEnum.LowercaseHash;
97101
var temp = Path.Combine (Path.GetTempPath (), Path.GetRandomFileName ());
98102
Directory.CreateDirectory (temp);
99103

100-
// We're going to do 3 steps here instead of separate tasks so
101-
// we can share the list of JLO TypeDefinitions between them
102-
var res = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols:true);
103-
104104
var selectedWhitelistAssemblies = new List<string> ();
105105

106106
// Put every assembly we'll need in the resolver

src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesigner.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,24 @@ public override bool Execute ()
106106
var assemblyNames = new List<string> ();
107107
if (IsApplication && References != null && References.Any ()) {
108108
// FIXME: should this be unified to some better code with ResolveLibraryProjectImports?
109-
var resolver = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols: false);
110-
foreach (var assemblyName in References) {
111-
var suffix = assemblyName.ItemSpec.EndsWith (".dll") ? String.Empty : ".dll";
112-
string hintPath = assemblyName.GetMetadata ("HintPath").Replace (Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
113-
string fileName = assemblyName.ItemSpec + suffix;
114-
resolver.Load (Path.GetFullPath (assemblyName.ItemSpec));
115-
if (!String.IsNullOrEmpty (hintPath) && !File.Exists (hintPath)) // ignore invalid HintPath
116-
hintPath = null;
117-
string assemblyPath = String.IsNullOrEmpty (hintPath) ? fileName : hintPath;
118-
if (MonoAndroidHelper.IsFrameworkAssembly (fileName) && !MonoAndroidHelper.FrameworkEmbeddedJarLookupTargets.Contains (Path.GetFileName (fileName)))
119-
continue;
120-
Log.LogDebugMessage ("Scan assembly {0} for resource generator", fileName);
121-
assemblyNames.Add (assemblyPath);
109+
using (var resolver = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols: false)) {
110+
foreach (var assemblyName in References) {
111+
var suffix = assemblyName.ItemSpec.EndsWith (".dll") ? String.Empty : ".dll";
112+
string hintPath = assemblyName.GetMetadata ("HintPath").Replace (Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
113+
string fileName = assemblyName.ItemSpec + suffix;
114+
resolver.Load (Path.GetFullPath (assemblyName.ItemSpec));
115+
if (!String.IsNullOrEmpty (hintPath) && !File.Exists (hintPath)) // ignore invalid HintPath
116+
hintPath = null;
117+
string assemblyPath = String.IsNullOrEmpty (hintPath) ? fileName : hintPath;
118+
if (MonoAndroidHelper.IsFrameworkAssembly (fileName) && !MonoAndroidHelper.FrameworkEmbeddedJarLookupTargets.Contains (Path.GetFileName (fileName)))
119+
continue;
120+
Log.LogDebugMessage ("Scan assembly {0} for resource generator", fileName);
121+
assemblyNames.Add (assemblyPath);
122+
}
123+
var assemblies = assemblyNames.Select (assembly => resolver.GetAssembly (assembly));
124+
new ResourceDesignerImportGenerator (Namespace, resources)
125+
.CreateImportMethods (assemblies);
122126
}
123-
var assemblies = assemblyNames.Select (assembly => resolver.GetAssembly (assembly));
124-
new ResourceDesignerImportGenerator (Namespace, resources)
125-
.CreateImportMethods (assemblies);
126127
}
127128

128129
AdjustConstructor (isFSharp, resources);

src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -363,28 +363,29 @@ public override bool Execute ()
363363
? CachePath
364364
: Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData), CacheBaseDir);
365365

366-
var resolver = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols: false);
367-
foreach (var assemblyItem in Assemblies) {
368-
string fullPath = Path.GetFullPath (assemblyItem.ItemSpec);
369-
if (assemblies.Contains (fullPath)) {
370-
LogDebugMessage (" Skip assembly: {0}, it was already processed", fullPath);
371-
continue;
372-
}
373-
assemblies.Add (fullPath);
374-
resolver.Load (fullPath);
375-
// Append source file name (without the Xamarin. prefix or extension) to the base folder
376-
// This would help avoid potential collisions.
377-
foreach (var ca in resolver.GetAssembly (assemblyItem.ItemSpec).CustomAttributes) {
378-
switch (ca.AttributeType.FullName) {
379-
case "Android.IncludeAndroidResourcesFromAttribute":
380-
AddAttributeValue (androidResources, ca, "XA5206", "{0}. Android resource directory {1} doesn't exist.", true, fullPath);
381-
break;
382-
case "Java.Interop.JavaLibraryReferenceAttribute":
383-
AddAttributeValue (javaLibraries, ca, "XA5207", "{0}. Java library file {1} doesn't exist.", false, fullPath);
384-
break;
385-
case "Android.NativeLibraryReferenceAttribute":
386-
AddAttributeValue (nativeLibraries, ca, "XA5210", "{0}. Native library file {1} doesn't exist.", false, fullPath);
387-
break;
366+
using (var resolver = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols: false)) {
367+
foreach (var assemblyItem in Assemblies) {
368+
string fullPath = Path.GetFullPath (assemblyItem.ItemSpec);
369+
if (assemblies.Contains (fullPath)) {
370+
LogDebugMessage (" Skip assembly: {0}, it was already processed", fullPath);
371+
continue;
372+
}
373+
assemblies.Add (fullPath);
374+
resolver.Load (fullPath);
375+
// Append source file name (without the Xamarin. prefix or extension) to the base folder
376+
// This would help avoid potential collisions.
377+
foreach (var ca in resolver.GetAssembly (assemblyItem.ItemSpec).CustomAttributes) {
378+
switch (ca.AttributeType.FullName) {
379+
case "Android.IncludeAndroidResourcesFromAttribute":
380+
AddAttributeValue (androidResources, ca, "XA5206", "{0}. Android resource directory {1} doesn't exist.", true, fullPath);
381+
break;
382+
case "Java.Interop.JavaLibraryReferenceAttribute":
383+
AddAttributeValue (javaLibraries, ca, "XA5207", "{0}. Java library file {1} doesn't exist.", false, fullPath);
384+
break;
385+
case "Android.NativeLibraryReferenceAttribute":
386+
AddAttributeValue (nativeLibraries, ca, "XA5210", "{0}. Native library file {1} doesn't exist.", false, fullPath);
387+
break;
388+
}
388389
}
389390
}
390391
}

src/Xamarin.Android.Build.Tasks/Tasks/LinkAssemblies.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,16 @@ public override bool Execute ()
7575
Log.LogDebugMessage (" DumpDependencies: {0}", DumpDependencies);
7676
Log.LogDebugMessage (" LinkOnlyNewerThan: {0}", LinkOnlyNewerThan);
7777

78-
var res = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols: false);
79-
78+
var rp = new ReaderParameters {
79+
InMemory = true,
80+
};
81+
using (var res = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols: false /* TODO, rp */)) {
82+
return Execute (res);
83+
}
84+
}
85+
86+
bool Execute (DirectoryAssemblyResolver res)
87+
{
8088
// Put every assembly we'll need in the resolver
8189
foreach (var assembly in ResolvedAssemblies) {
8290
res.Load (Path.GetFullPath (assembly.ItemSpec));

src/Xamarin.Android.Build.Tasks/Tasks/ResolveAssemblies.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,21 @@ public class ResolveAssemblies : Task
4242
[Output]
4343
public string[] ResolvedDoNotPackageAttributes { get; set; }
4444

45-
DirectoryAssemblyResolver resolver;
46-
4745
public override bool Execute ()
46+
{
47+
using (var resolver = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols: false)) {
48+
return Execute (resolver);
49+
}
50+
}
51+
52+
bool Execute (DirectoryAssemblyResolver resolver)
4853
{
4954
Log.LogDebugMessage ("ResolveAssemblies Task");
5055
Log.LogDebugMessage (" ReferenceAssembliesDirectory: {0}", ReferenceAssembliesDirectory);
5156
Log.LogDebugMessage (" I18nAssemblies: {0}", I18nAssemblies);
5257
Log.LogDebugMessage (" LinkMode: {0}", LinkMode);
5358
Log.LogDebugTaskItems (" Assemblies:", Assemblies);
5459

55-
resolver = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols: false);
5660
foreach (var dir in ReferenceAssembliesDirectory.Split (new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
5761
resolver.SearchDirectories.Add (dir);
5862

@@ -80,14 +84,14 @@ public override bool Execute ()
8084
}
8185
try {
8286
foreach (var assembly in topAssemblyReferences)
83-
AddAssemblyReferences (assemblies, assembly, true);
87+
AddAssemblyReferences (resolver, assemblies, assembly, true);
8488
} catch (Exception ex) {
8589
Log.LogError ("Exception while loading assemblies: {0}", ex);
8690
return false;
8791
}
8892

8993
// Add I18N assemblies if needed
90-
AddI18nAssemblies (assemblies);
94+
AddI18nAssemblies (resolver, assemblies);
9195

9296
ResolvedAssemblies = assemblies.Select (a => new TaskItem (a)).ToArray ();
9397
ResolvedSymbols = assemblies.Select (a => a + ".mdb").Where (a => File.Exists (a)).Select (a => new TaskItem (a)).ToArray ();
@@ -100,13 +104,13 @@ public override bool Execute ()
100104
Log.LogDebugTaskItems (" [Output] ResolvedFrameworkAssemblies:", ResolvedFrameworkAssemblies);
101105
Log.LogDebugTaskItems (" [Output] ResolvedDoNotPackageAttributes:", ResolvedDoNotPackageAttributes);
102106

103-
return true;
107+
return !Log.HasLoggedErrors;
104108
}
105109

106110
readonly List<string> do_not_package_atts = new List<string> ();
107111
int indent = 2;
108112

109-
private void AddAssemblyReferences (ICollection<string> assemblies, AssemblyDefinition assembly, bool topLevel)
113+
void AddAssemblyReferences (DirectoryAssemblyResolver resolver, ICollection<string> assemblies, AssemblyDefinition assembly, bool topLevel)
110114
{
111115
var fqname = assembly.MainModule.FullyQualifiedName;
112116

@@ -130,7 +134,7 @@ private void AddAssemblyReferences (ICollection<string> assemblies, AssemblyDefi
130134
// Recurse into each referenced assembly
131135
foreach (AssemblyNameReference reference in assembly.MainModule.AssemblyReferences) {
132136
var reference_assembly = resolver.Resolve (reference);
133-
AddAssemblyReferences (assemblies, reference_assembly, false);
137+
AddAssemblyReferences (resolver, assemblies, reference_assembly, false);
134138
}
135139
indent -= 2;
136140
}
@@ -147,7 +151,7 @@ static LinkModes ParseLinkMode (string linkmode)
147151
return mode;
148152
}
149153

150-
private void AddI18nAssemblies (ICollection<string> assemblies)
154+
void AddI18nAssemblies (DirectoryAssemblyResolver resolver, ICollection<string> assemblies)
151155
{
152156
var i18n = Linker.ParseI18nAssemblies (I18nAssemblies);
153157
var link = ParseLinkMode (LinkMode);
@@ -156,25 +160,25 @@ private void AddI18nAssemblies (ICollection<string> assemblies)
156160
if (i18n == Mono.Linker.I18nAssemblies.None)
157161
return;
158162

159-
assemblies.Add (ResolveI18nAssembly ("I18N"));
163+
assemblies.Add (ResolveI18nAssembly (resolver, "I18N"));
160164

161165
if (i18n.HasFlag (Mono.Linker.I18nAssemblies.CJK))
162-
assemblies.Add (ResolveI18nAssembly ("I18N.CJK"));
166+
assemblies.Add (ResolveI18nAssembly (resolver, "I18N.CJK"));
163167

164168
if (i18n.HasFlag (Mono.Linker.I18nAssemblies.MidEast))
165-
assemblies.Add (ResolveI18nAssembly ("I18N.MidEast"));
169+
assemblies.Add (ResolveI18nAssembly (resolver, "I18N.MidEast"));
166170

167171
if (i18n.HasFlag (Mono.Linker.I18nAssemblies.Other))
168-
assemblies.Add (ResolveI18nAssembly ("I18N.Other"));
172+
assemblies.Add (ResolveI18nAssembly (resolver, "I18N.Other"));
169173

170174
if (i18n.HasFlag (Mono.Linker.I18nAssemblies.Rare))
171-
assemblies.Add (ResolveI18nAssembly ("I18N.Rare"));
175+
assemblies.Add (ResolveI18nAssembly (resolver, "I18N.Rare"));
172176

173177
if (i18n.HasFlag (Mono.Linker.I18nAssemblies.West))
174-
assemblies.Add (ResolveI18nAssembly ("I18N.West"));
178+
assemblies.Add (ResolveI18nAssembly (resolver, "I18N.West"));
175179
}
176180

177-
private string ResolveI18nAssembly (string name)
181+
string ResolveI18nAssembly (DirectoryAssemblyResolver resolver, string name)
178182
{
179183
var assembly = resolver.Resolve (AssemblyNameReference.Parse (name));
180184
return assembly.MainModule.FullyQualifiedName;

src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ public override bool Execute ()
7171
var resolvedResourceDirectories = new List<string> ();
7272
var resolvedAssetDirectories = new List<string> ();
7373
var resolvedEnvironmentFiles = new List<string> ();
74-
Extract (jars, resolvedResourceDirectories, resolvedAssetDirectories, resolvedEnvironmentFiles);
74+
75+
using (var resolver = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols: false)) {
76+
Extract (resolver, jars, resolvedResourceDirectories, resolvedAssetDirectories, resolvedEnvironmentFiles);
77+
}
7578

7679
Jars = jars.ToArray ();
7780
ResolvedResourceDirectories = resolvedResourceDirectories
@@ -133,6 +136,7 @@ static string GetTargetAssembly (ITaskItem assemblyName)
133136

134137
// Extracts library project contents under e.g. obj/Debug/[__library_projects__/*.jar | res/*/*]
135138
void Extract (
139+
DirectoryAssemblyResolver res,
136140
ICollection<string> jars,
137141
ICollection<string> resolvedResourceDirectories,
138142
ICollection<string> resolvedAssetDirectories,
@@ -142,7 +146,6 @@ void Extract (
142146
if (!outdir.Exists)
143147
outdir.Create ();
144148

145-
var res = new DirectoryAssemblyResolver (Log.LogWarning, loadDebugSymbols: false);
146149
foreach (var assembly in Assemblies)
147150
res.Load (assembly.ItemSpec);
148151

src/Xamarin.Android.Build.Tasks/Tasks/StripEmbeddedLibraries.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ public override bool Execute ()
2828
Log.LogDebugMessage ("StripEmbeddedLibraries Task");
2929
Log.LogDebugTaskItems (" Assemblies: ", Assemblies);
3030

31-
var res = new DirectoryAssemblyResolver (Log.LogWarning, true);
31+
using (var res = new DirectoryAssemblyResolver (Log.LogWarning, true)) {
32+
return Execute (res);
33+
}
34+
}
35+
36+
bool Execute (DirectoryAssemblyResolver res)
37+
{
3238
foreach (var assembly in Assemblies)
3339
res.Load (Path.GetFullPath (assembly.ItemSpec));
3440

0 commit comments

Comments
 (0)