-
Notifications
You must be signed in to change notification settings - Fork 533
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
[XABT] Use ZipArchive to build APKs. #9623
base: main
Are you sure you want to change the base?
Conversation
9a52e1c
to
6194d12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also make a backup MSBuild property to fallback to libZipSharp
? Something private like $(_AndroidUseLibZipSharp)
?
This is just in case something goes wrong in a release, we can give a customer this property to work around something broken.
One of the reasons we didn't use System.IO.Compression was because it IGNORED per file compression settings it also failed to actually STORE things when NoCompression was defined (it would always compress files), this would break out native library support in all sorts of weird ways. If the plan is to use this when we are going to need to make sure the test coverage is making sure we can add files which have no compression and that they are actually stored as such. //cc @grendello |
@dellis1972 I think he figured out how to set the compression method now:
|
Thanks for the context. I'll do some testing around |
@jpobst it might be enough to verify in some of our build tests that the compression method is correct. We have a couple like this: android/tests/MSBuildDeviceIntegration/Tests/BundleToolTests.cs Lines 299 to 307 in de04316
|
I believe I see the issue that @dellis1972 is referring to. Building with
However, using
It's like it's running it through the compression algorithm with a compression level of 0 instead of placing it unmodified inside the archive. EDIT: Indeed it seems like this was the original behavior and it was fixed in .NET Core 3.0: dotnet/runtime#26185 I think we have 2 options here:
|
Could we include the source from the “good” System.IO.Compression in src-ThirdParty? Then we could also avoid System.Reflection by making some new public member. |
I think the biggest issue is we need it to run on I think we would likely be venturing into undesirable territory trying to ship our own. If we moved it out-of-process, we could eliminate the CRC reflection because a new property exists. There still isn't a property for the compression method, but we could possibly apply some pressure on this issue for .NET 10. (We use the CRC and CompressionMethod to check if we need to update existing entries in an archive during incremental builds.) |
Yeah, so I wouldn't try to bring their code in. Maybe out-of-process is a good option? They are doing this for components inside Visual Studio as well. A new console app could do the work of the MSBuild task, and could always run under .NET 10+ and not .NET framework at all. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.
Files not reviewed (1)
- src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets: Language not supported
It would appear we no longer require features not available in
System.IO.Compression.ZipArchive
in order to build.apk
/.aab
files. Additionally, it appears thatZipArchive
is noticeably faster than our current usage ofLibZipSharp
. Switch theBuildArchive
task to preferringZipArchive
overLibZipSharp
when possible for building APKs. TheLibZipSharp
implementation is maintained as a fallback and in case future new.apk
/.aab
requirements necessitate its use.Archive sizes for
.apk
increase 1.3%-2.7% which seems acceptable..aab
sizes remain roughly the same, likely becausebundletool
repacks them.Implementation Notes
netstandard2.0
does not expose API for examining aCRC
orCompressionMethod
of an existing entry in a Zip file, though bothnet472
andnet9.0
have private fields. As such, we use reflection to access these private fields. If the runtime we are using does not have these fields, we will fall back to usingLibZipSharp
as we do now.IZipArchive
so that we can switch betweenSystem.IO.Compression.ZipFile
andLibZipSharp
as needed.LibZipSharp
with$(_AndroidUseLibZipSharp)
=true
.Performance
Measurements of the
BuildArchive
task when using theandroid
template for initial and incremental build scenarios.Debug - FastDev
main
Debug - EmbedAssembliesInApk
main
Release
main
CI build that falls back to
LibZipSharp
to ensure it still passes our tests: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=10720142