From a7e54b6bdc443aeb6bbbc5dfff6a94e5b1496a53 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Tue, 21 Mar 2023 14:55:25 +0000 Subject: [PATCH] [Xamarin.Android.Build.Tasks] Fix AndroidPackagingOptionsExclude Fixes https://github.com/xamarin/xamarin-android/issues/7902 Commit 2726a386 introduced the ability to ignore certain file patterns when adding files to an apk. Unfortunately it had a bug in the code and the test. The code would log a warning that is was ignoring the file, but then add the file anyway. The test was looking for the wrong path in the apk , so it would always pass the test. This commit fixes both of these issues. --- src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs | 6 +++++- .../Tests/Xamarin.Android.Build.Tests/PackagingTest.cs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs b/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs index 4065ba1ef8d..3b9b763d3af 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs @@ -254,12 +254,16 @@ void ExecuteWithAbi (string [] supportedAbis, string apkInputPath, string apkOut continue; } // check for ignored items + bool exclude = false; foreach (var pattern in excludePatterns) { if(pattern.IsMatch (path)) { Log.LogDebugMessage ($"Ignoring jar entry '{name}' from '{Path.GetFileName (jarFile)}'. Filename matched the exclude pattern '{pattern}'."); - continue; + exclude = true; + break; } } + if (exclude) + continue; if (string.Compare (Path.GetFileName (name), "AndroidManifest.xml", StringComparison.OrdinalIgnoreCase) == 0) { Log.LogDebugMessage ("Ignoring jar entry {0} from {1}: the same file already exists in the apk", name, Path.GetFileName (jarFile)); continue; diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs index 0d04960bb38..c69455160ff 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs @@ -931,7 +931,7 @@ public void CheckExcludedFilesAreMissing () string expected = $"Ignoring jar entry 'kotlin/Error.kotlin_metadata'"; Assert.IsTrue (b.LastBuildOutput.ContainsText (expected), $"Error.kotlin_metadata should have been ignored."); using (var zip = ZipHelper.OpenZip (apk)) { - Assert.IsFalse (zip.ContainsEntry ("Error.kotlin_metadata"), "Error.kotlin_metadata should have been ignored."); + Assert.IsFalse (zip.ContainsEntry ("kotlin/Error.kotlin_metadata"), "Error.kotlin_metadata should have been ignored."); } } }