dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 528 forks source link

'Compression method not supported' building inside VS #6950

Open jonathanpeppers opened 2 years ago

jonathanpeppers commented 2 years ago

Android application type

Android for .NET (net6.0-android, etc.)

Affected platform version

.NET 6

Description

Originally posted by @rsfitzii at:

https://github.com/dotnet/maui/issues/6254

It appears that building an Android project in VS fails for a customer, but works with both command-line dotnet build or .NET Framework MSBuild...

C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.300-rc.1.4\tools\Xamarin.Android.EmbeddedResource.targets(36,5): error XARLP7000: Xamarin.Tools.Zip.ZipException: Compression method not supported
   at Xamarin.Tools.Zip.ZipArchive.AddStream(Stream stream, String archivePath, EntryPermissions permissions, CompressionMethod compressionMethod, Boolean overwriteExisting, Nullable`1 modificationTime) in /Users/runner/work/1/s/LibZipSharp/Xamarin.Tools.Zip/ZipArchive.cs:line 353
   at Xamarin.Tools.Zip.ZipArchive.AddFile(String sourcePath, String archivePath, EntryPermissions permissions, CompressionMethod compressionMethod, Boolean overwriteExisting) in /Users/runner/work/1/s/LibZipSharp/Xamarin.Tools.Zip/ZipArchive.cs:line 417
   at Xamarin.Android.Tasks.ZipArchiveEx.AddFileAndFlush(String filename, Int64 fileLength, String archiveFileName, CompressionMethod compressionMethod)
   at Xamarin.Android.Tasks.ZipArchiveEx.AddFiles(String folder, String folderInArchive, CompressionMethod method)
   at Xamarin.Android.Tasks.ZipArchiveEx.AddDirectory(String folder, String folderInArchive, CompressionMethod method)
   at Xamarin.Android.Tasks.ResolveLibraryProjectImports.<>c__DisplayClass67_0.<CreateResourceArchive>b__0(String f)
   at Microsoft.Android.Build.Tasks.Files.ArchiveZipUpdate(String target, Action`1 archiver) in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/Files.cs:line 94
   at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Extract(IDictionary`2 jars, ICollection`1 resolvedResourceDirectories, ICollection`1 resolvedAssetDirectories, ICollection`1 resolvedEnvironments)
   at Xamarin.Android.Tasks.ResolveLibraryProjectImports.RunTask()
   at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17 [C:\Users\scottf\Documents\mpcgolf\test2\test2.csproj]

Steps to Reproduce

I'm not able to reproduce this myself. The customer builds inside Visual Studio to hit the issue.

Did you find any workaround?

No response

Relevant log output

Logs: Binlogs.zip

dellis1972 commented 2 years ago

@grendello this looks very weird.

Looking at the code we are asking for the Default compression method in CreateResourceArchive see https://github.com/xamarin/xamarin-android/blob/fd5f31cc89648957243f31ba8fd7af7fccba11e4/src/Xamarin.Android.Build.Tasks/Utilities/ZipArchiveEx.cs#L100

Not sure why this would happen in just the IDE....

grendello commented 2 years ago

@dellis1972 from reading the code, I think it's one of the extra fields that causes the issue - the exception is thrown after this code fails, however zip_file_extra_field_set is not documented to return the "invalid compression method" error. Unless we get ZIP_ER_INVAL and for some reason interpret it as "invalid compression method". The exception message might be a red herring. As to why it would happen only under IDE... maybe, for some reason, VS has a different version of LibZipSharp loaded in memory that is used instead of what XA ships and XA tasks assume they're using?

dellis1972 commented 2 years ago

this code

Its possible that its hitting a different version of LibZipSharp, but we've not bumped that for a while now I think.

grendello commented 2 years ago

TBH, the error makes no sense in the context of the code path described by the exception stack trace...

dellis1972 commented 2 years ago

Indeed. That was confusing me as well.

The other posibility is that the wrong libzip dll is being loaded somehow and its reporting a different code back 🤷

juanredondo commented 1 year ago

I'm experiencing the same issue, but in Visual Studio 2022 Professional while implementing Xamarin.Forms on Android. If you'd like, I can provide any necessary logs or similar information you may need, as this development blockage is affecting me greatly.

samhouts commented 1 year ago

Another report was made here: https://developercommunity.visualstudio.com/t/MAUI-Android-project-build-fails-with-er/10471078