Skip to content

Commit a526dd5

Browse files
[xabt] fall back to libZipSharp on .NET framework (#10238)
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.
1 parent f9c53bb commit a526dd5

File tree

1 file changed

+8
-31
lines changed

1 file changed

+8
-31
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/BuildArchive.cs

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -216,39 +216,16 @@ bool ShouldFallbackToLibZipSharp ()
216216
return true;
217217
}
218218

219-
// .NET 6+ handles uncompressed files correctly, so we don't need to fallback.
220-
if (RuntimeInformation.FrameworkDescription == ".NET") {
221-
Log.LogDebugMessage ("Using System.IO.Compression because we're running on .NET 6+.");
222-
return false;
223-
}
224-
225-
// Nothing is going to get written uncompressed, so we don't need to fallback.
226-
if (uncompressedMethod != CompressionMethod.Store) {
227-
Log.LogDebugMessage ("Using System.IO.Compression because uncompressedMethod isn't 'Store'.");
228-
return false;
229-
}
230-
231-
// No uncompressed file extensions were specified, so we don't need to fallback.
232-
if (UncompressedFileExtensionsSet.Count == 0) {
233-
Log.LogDebugMessage ("Using System.IO.Compression because no uncompressed file extensions were specified.");
234-
return false;
235-
}
236-
237-
// See if any of the files to be added need to be uncompressed.
238-
foreach (var file in FilesToAddToArchive) {
239-
var file_path = file.ItemSpec;
240-
241-
// Handle files from inside a .jar/.aar
242-
if (file.GetMetadataOrDefault ("JavaArchiveEntry", (string?)null) is string jar_entry_name)
243-
file_path = jar_entry_name;
244-
245-
if (UncompressedFileExtensionsSet.Contains (Path.GetExtension (file_path))) {
246-
Log.LogDebugMessage ($"Falling back to LibZipSharp because '{file_path}' needs to be stored uncompressed.");
247-
return true;
248-
}
219+
// Always fallback on .NET Framework
220+
var frameworkDescription = RuntimeInformation.FrameworkDescription;
221+
Log.LogDebugMessage ($"RuntimeInformation.FrameworkDescription: {frameworkDescription}");
222+
if (frameworkDescription != ".NET") {
223+
Log.LogDebugMessage ("Falling back to LibZipSharp because we are *not* running on .NET 6+.");
224+
return true;
249225
}
250226

251-
Log.LogDebugMessage ("Using System.IO.Compression because no files need to be stored uncompressed.");
227+
// .NET 6+ handles uncompressed files correctly, so we don't need to fallback.
228+
Log.LogDebugMessage ("Using System.IO.Compression because we're running on .NET 6+.");
252229
return false;
253230
}
254231

0 commit comments

Comments
 (0)