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

Conversation

jonathanpeppers
Copy link
Member

Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2510554

In testing .NET 10, we found the issue:

ADB0010: Mono.AndroidTools.InstallFailedException: Unexpected install
output: Failure [-124: Failed parse during installPackageLI: Targeting
R+ (version 30 and above) requires the resources.arsc of installed
APKs to be stored uncompressed and aligned on a 4-byte boundary] ...
  1. Create a new .NET MAUI/MAUI Blazor app.
  2. Change the value for the Color attribute to #FF0000 or any color.
<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#FF0000" BaseSize="128,128" />
  1. Deploy to android.
  2. The splash screen color should change according to the chosen color.
  3. Stop Debugging and change the splash screen color again.
  4. If you do it enough times, you would encounter the error.

Manually, adding $(_AndroidUseLibZipSharp) to the .csproj file solves the issue:

<_AndroidUseLibZipSharp>true</_AndroidUseLibZipSharp>

Reviewing, a .binlog created by setting %MSBUILDDEBUGENGINE%=1 and launching Visual Studio, we see the message:

Task BuildArchive
...
Using System.IO.Compression because no uncompressed file extensions were specified.

So, we are relying on .NET Framework's System.IO.Compression to handle .apk creation in some cases. libZipSharp was created because of bugs in .NET Framework's & Mono's implementation of System.IO.Compression that caused issues with Android packaging.

To fix this, we will always use libZipSharp for .NET Framework, regardless if files are compressed or not.

Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2510554

In testing .NET 10, we found the issue:

    ADB0010: Mono.AndroidTools.InstallFailedException: Unexpected install
    output: Failure [-124: Failed parse during installPackageLI: Targeting
    R+ (version 30 and above) requires the resources.arsc of installed
    APKs to be stored uncompressed and aligned on a 4-byte boundary] ...

1. Create a new .NET MAUI/MAUI Blazor app.
2. Change the value for the Color attribute to #FF0000 or any color.
```xml
<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#FF0000" BaseSize="128,128" />
```
3. Deploy to android.
4. The splash screen color should change according to the chosen color.
5. Stop Debugging and change the splash screen color again.
6. If you do it enough times, you would encounter the error.

Manually, adding `$(_AndroidUseLibZipSharp)` to the `.csproj` file
solves the issue:

    <_AndroidUseLibZipSharp>true</_AndroidUseLibZipSharp>

Reviewing, a `.binlog` created by setting `%MSBUILDDEBUGENGINE%=1` and
launching Visual Studio, we see the message:

    Task BuildArchive
    ...
    Using System.IO.Compression because no uncompressed file extensions were specified.

So, we are relying on .NET Framework's `System.IO.Compression` to
handle `.apk` creation in some cases. `libZipSharp` *was created*
because of bugs in .NET Framework's & Mono's implementation of
`System.IO.Compression` that caused issues with Android packaging.

To fix this, we will always use `libZipSharp` for .NET Framework,
regardless if files are compressed or not.
}

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.

@jonathanpeppers jonathanpeppers merged commit 1d22ff8 into main Jun 24, 2025
59 checks passed
@jonathanpeppers jonathanpeppers deleted the dev/peppers/libZipSharp branch June 24, 2025 13:12
jonathanpeppers added a commit that referenced this pull request Jun 24, 2025
Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2510554

In testing .NET 10, we found the issue:

    ADB0010: Mono.AndroidTools.InstallFailedException: Unexpected install
    output: Failure [-124: Failed parse during installPackageLI: Targeting
    R+ (version 30 and above) requires the resources.arsc of installed
    APKs to be stored uncompressed and aligned on a 4-byte boundary] ...

1. Create a new .NET MAUI/MAUI Blazor app.
2. Change the value for the Color attribute to #FF0000 or any color.
```xml
<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#FF0000" BaseSize="128,128" />
```
3. Deploy to android.
4. The splash screen color should change according to the chosen color.
5. Stop Debugging and change the splash screen color again.
6. If you do it enough times, you would encounter the error.

Manually, adding `$(_AndroidUseLibZipSharp)` to the `.csproj` file
solves the issue:

    <_AndroidUseLibZipSharp>true</_AndroidUseLibZipSharp>

Reviewing, a `.binlog` created by setting `%MSBUILDDEBUGENGINE%=1` and
launching Visual Studio, we see the message:

    Task BuildArchive
    ...
    Using System.IO.Compression because no uncompressed file extensions were specified.

So, we are relying on .NET Framework's `System.IO.Compression` to
handle `.apk` creation in some cases. `libZipSharp` *was created*
because of bugs in .NET Framework's & Mono's implementation of
`System.IO.Compression` that caused issues with Android packaging.

To fix this, we will always use `libZipSharp` for .NET Framework,
regardless if files are compressed or not.
@github-actions github-actions bot locked and limited conversation to collaborators Jul 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants