Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Fix AndroidPackagingOptionsExclude (#7903)
Browse files Browse the repository at this point in the history
Fixes #7902

Commit 2726a38 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.
  • Loading branch information
dellis1972 authored Mar 21, 2023
1 parent f3592b3 commit f3c21a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
}
Expand Down

0 comments on commit f3c21a6

Please sign in to comment.