From 4c81668448cc097729f04d94bdccb4af04158582 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Mon, 16 May 2016 11:38:28 -0400 Subject: [PATCH] [Xamarin.Android.Build.Tasks] Extract resources with S.I.C.ZipFile. (#41) Ionic.Zip.dll, as provided by the Unofficial.Ionic.Zip 1.9.1.8 NuGet package, is broken. [It hardcodes `\` as directory separator char][0], which breaks all manner of things, and when we try to extract and unzip embedded resources from assemblies, it fails: Error executing task ResolveLibraryProjectImports: System.ArgumentException: Path is empty at System.IO.Directory.CreateDirectory (System.String path) <0x1a20ca0 + 0x0011c> in :0 at Ionic.Zip.ZipEntry.InternalExtract (System.String baseDir, System.IO.Stream outstream, System.String password) <0x3af4b78 + 0x002e7> in :0 I'm not sure *why* "path is empty" -- the callstack isn't very helpful -- but it *is* empty, which means if a project references an assembly which contains e.g. @(AndroidResource), everthing breaks. Fix the `ResolveLibraryProjectImports` task so that instead of using Ionic.Zip.dll to extract embedded resources we instead use System.IO.Compression.ZipFile (in System.IO.Compression.FileSystem.dll, new in .NET 4.5). Note: *Other* uses of Ionic.Zip.dll are similarly suspect but *are not fixed*. Fixing (removing?) Ionic.Zip.dll will be done later. [0]: https://gitter.im/xamarin/xamarin-android?at=572d97caf36daf63798d6033 --- .../Tasks/ResolveLibraryProjectImports.cs | 6 ++---- .../Xamarin.Android.Build.Tasks.csproj | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs index 0fb9d477339..277ccfbd5be 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.IO.Compression; using System.Linq; using System.Xml; using System.Xml.Linq; @@ -9,7 +10,6 @@ using Microsoft.Build.Utilities; using Microsoft.Build.Framework; using System.Text.RegularExpressions; -using Ionic.Zip; using Java.Interop.Tools.Cecil; @@ -232,9 +232,7 @@ void Extract ( // temporarily extracted directory will look like: // __library_projects__/[dllname]/[library_project_imports | jlibs]/bin - using (var zip = new ZipFile (finfo.FullName)) { - Files.ExtractAll (zip, outDirForDll); - } + ZipFile.ExtractToDirectory (finfo.FullName, outDirForDll); // We used to *copy* the resources to overwrite other resources, // which resulted in missing resource issue. diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj index 4a605731254..e5dd40fb953 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj @@ -40,6 +40,8 @@ + +