Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] ignore aapt/AndroidManifest.xml
Browse files Browse the repository at this point in the history
Context: https://stackoverflow.com/questions/41592744/function-of-aapt-androidmanifest-xml-in-aar
Fixes: dotnet#2141

Apparently Android Studio is now shipping a duplicate, pre-formatted
`AndroidManifest.xml` file, inside of AAR files. Its purpose is to be
used with `aapt` invocations, since errors may be thrown related to
`{` or `}` characters.

Since this file may exist in AAR files used by Xamarin.Android, we
should ignore `aapt/AndroidManifest.xml` files the same way we ignore
them inside `manifest` or `bin` directories.

Changes:
- Added a `IgnoredManifestDirectories` list, since we are getting to a
  point where `!= && != && !=` would be a lot of noise.
- Switched the LINQ expression to simple `foreach` loop, which should
  also give a slight performance benefit.
  • Loading branch information
jonathanpeppers committed Sep 4, 2018
1 parent c2d3681 commit 8f8903a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Xamarin.Android.Build.Tasks/Tasks/GetImportedLibraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ namespace Xamarin.Android.Tasks
{
public class GetImportedLibraries : Task
{
static readonly string [] IgnoredManifestDirectories = new [] {
"bin",
"manifest",
"aapt",
};

[Required]
public string TargetDirectory { get; set; }

Expand All @@ -37,13 +43,14 @@ public override bool Execute ()
return true;
}
// there could be ./AndroidManifest.xml and bin/AndroidManifest.xml, which will be the same. So, ignore "bin" ones.
ManifestDocuments = Directory.GetFiles (TargetDirectory, "AndroidManifest.xml", SearchOption.AllDirectories)
.Where (f => {
var directory = Path.GetFileName (Path.GetDirectoryName (f));
return directory != "bin" && directory != "manifest";
})
.Select (p => new TaskItem (p))
.ToArray ();
var manifestDocuments = new List<ITaskItem> ();
foreach (var f in Directory.EnumerateFiles (TargetDirectory, "AndroidManifest.xml", SearchOption.AllDirectories)) {
var directory = Path.GetFileName (Path.GetDirectoryName (f));
if (IgnoredManifestDirectories.Contains (directory))
continue;
manifestDocuments.Add (new TaskItem (f));
}
ManifestDocuments = manifestDocuments.ToArray ();
NativeLibraries = Directory.GetFiles (TargetDirectory, "*.so", SearchOption.AllDirectories)
.Where (p => MonoAndroidHelper.GetNativeLibraryAbi (p) != null)
.Select (p => new TaskItem (p)).ToArray ();
Expand Down

0 comments on commit 8f8903a

Please sign in to comment.