Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] ignore aapt/AndroidManifest.xml (#2144)
Browse files Browse the repository at this point in the history
* [Xamarin.Android.Build.Tasks] ignore aapt/AndroidManifest.xml

Context: https://stackoverflow.com/questions/41592744/function-of-aapt-androidmanifest-xml-in-aar
Fixes: #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.

* Fix test on MacOS
  • Loading branch information
jonathanpeppers authored and dellis1972 committed Sep 7, 2018
1 parent 2214fac commit f6c3288
Show file tree
Hide file tree
Showing 3 changed files with 58 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
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,26 @@ public void ApplicationIdPlaceholder ()
builder.Dispose ();
}

[Test]
public void ExtraAaptManifest ()
{
var proj = new XamarinAndroidApplicationProject ();
proj.MainActivity = proj.DefaultMainActivity.Replace ("base.OnCreate (bundle);", "base.OnCreate (bundle);\nCrashlytics.Crashlytics.HandleManagedExceptions();");
proj.PackageReferences.Add (KnownPackages.Xamarin_Android_Crashlytics_2_9_4);
proj.PackageReferences.Add (KnownPackages.Xamarin_Android_Fabric_1_4_3);
proj.PackageReferences.Add (KnownPackages.Xamarin_Build_Download_0_4_11);
using (var builder = CreateApkBuilder (Path.Combine ("temp", TestName))) {
builder.RequiresMSBuild = true;
builder.Target = "Restore";
Assert.IsTrue (builder.Build (proj), "Restore should have succeeded.");
builder.Target = "Build";
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
var manifest = File.ReadAllText (Path.Combine (Root, builder.ProjectDirectory, "obj", "Debug", "android", "AndroidManifest.xml"));
Assert.IsTrue (manifest.Contains ("android:authorities=\"UnnamedProject.UnnamedProject.crashlyticsinitprovider\""), "placeholder not replaced");
Assert.IsFalse (manifest.Contains ("dollar_openBracket_applicationId_closeBracket"), "`aapt/AndroidManifest.xml` not ignored");
}
}

[Test]
public void ResourceExtraction ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,30 @@ public static class KnownPackages
}
}
};
public static Package Xamarin_Android_Crashlytics_2_9_4 = new Package {
Id = "Xamarin.Android.Crashlytics",
Version = "2.9.4",
TargetFramework = "MonoAndroid60",
References = {
new BuildItem.Reference("Xamarin.Android.Crashlytics") {
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Crashlytics.2.9.4\\lib\\MonoAndroid60\\Xamarin.Android.Crashlytics.dll"
}
}
};
public static Package Xamarin_Android_Fabric_1_4_3 = new Package {
Id = "Xamarin.Android.Fabric",
Version = "1.4.3",
TargetFramework = "MonoAndroid60",
References = {
new BuildItem.Reference("Xamarin.Android.Fabric") {
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Fabric.1.4.3\\lib\\MonoAndroid60\\Xamarin.Android.Fabric.dll"
}
}
};
public static Package Xamarin_Build_Download_0_4_11 = new Package {
Id = "Xamarin.Build.Download",
Version = "0.4.11",
};
}
}

0 comments on commit f6c3288

Please sign in to comment.