Skip to content

[xabt] fall back to libZipSharp on .NET framework #10238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2025
Merged
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
39 changes: 8 additions & 31 deletions src/Xamarin.Android.Build.Tasks/Tasks/BuildArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,39 +216,16 @@ bool ShouldFallbackToLibZipSharp ()
return true;
}

// .NET 6+ handles uncompressed files correctly, so we don't need to fallback.
if (RuntimeInformation.FrameworkDescription == ".NET") {
Log.LogDebugMessage ("Using System.IO.Compression because we're running on .NET 6+.");
return false;
}

// Nothing is going to get written uncompressed, so we don't need to fallback.
if (uncompressedMethod != CompressionMethod.Store) {
Log.LogDebugMessage ("Using System.IO.Compression because uncompressedMethod isn't 'Store'.");
return false;
}

// No uncompressed file extensions were specified, so we don't need to fallback.
if (UncompressedFileExtensionsSet.Count == 0) {
Log.LogDebugMessage ("Using System.IO.Compression because no uncompressed file extensions were specified.");
return false;
}

// See if any of the files to be added need to be uncompressed.
foreach (var file in FilesToAddToArchive) {
var file_path = file.ItemSpec;

// Handle files from inside a .jar/.aar
if (file.GetMetadataOrDefault ("JavaArchiveEntry", (string?)null) is string jar_entry_name)
file_path = jar_entry_name;

if (UncompressedFileExtensionsSet.Contains (Path.GetExtension (file_path))) {
Log.LogDebugMessage ($"Falling back to LibZipSharp because '{file_path}' needs to be stored uncompressed.");
return true;
}
// Always fallback on .NET Framework
var frameworkDescription = RuntimeInformation.FrameworkDescription;
Log.LogDebugMessage ($"RuntimeInformation.FrameworkDescription: {frameworkDescription}");
if (frameworkDescription != ".NET") {
Log.LogDebugMessage ("Falling back to LibZipSharp because we are *not* running on .NET 6+.");
return true;
}

Log.LogDebugMessage ("Using System.IO.Compression because no files need to be stored uncompressed.");
// .NET 6+ handles uncompressed files correctly, so we don't need to fallback.
Log.LogDebugMessage ("Using System.IO.Compression because we're running on .NET 6+.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there still a problem with Store in S.I.C ? Or was that fixed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store won't work with .NET framework, for sure. (it also apparently has a new incremental build bug!)

Looking at the old code it did this and returned early for dotnet build:

// .NET 6+ handles uncompressed files correctly, so we don't need to fallback.
if (RuntimeInformation.FrameworkDescription == ".NET") {
	Log.LogDebugMessage ("Using System.IO.Compression because we're running on .NET 6+.");
	return false;
}

I'm just trying to simplify this and return false for dotnet build and true for .NET framework MSBuild.exe.

Original commit is: 7454deb

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the line I'm concerned about as https://github.com/dotnet/android/pull/10238/files#diff-3f37e0c1a08fa8b4e139bfec5e8b490cd49e013ad631112ab3dacaf416c3bd83L226 which returned false if Store was NOT used. So if store was used we would fallback to libZipSharp.

Copy link
Contributor

@dellis1972 dellis1972 Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if there was any content which needed to be stored we would use libZipSharp because S.I.C even on .net 6+ didn't do that properly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is named backwards imo, but it’s ShouldFallbackToLibZipSharp and true uses LibZipSharp and false System.IO.

return false;
}

Expand Down
Loading