From 6a323e3eae30277b111a1e385cfaaab0e313f244 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Tue, 13 Feb 2018 13:56:56 +0000 Subject: [PATCH 1/2] [Xamarin.Android.Build.Tasks] Only report `ndk-bundle` if required. We should only list `ndk-bundle` in the AndroidDependencies if the user is using Aot or MkBundle. Otherwise we will end up downloading a ton of stuff we don't need. This commit fixes the `CalculateProjectDependencies` to report `ndk-bundle` if needed. It also adds a unit test to make sure it is not included when it shouldn't be. --- .../Tasks/CalculateProjectDependencies.cs | 4 +- .../GetDependenciesTests.cs | 42 +++++++++++++++++++ .../Xamarin.Android.Common.targets | 3 ++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CalculateProjectDependencies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CalculateProjectDependencies.cs index 2fad92a8a01..0d94bca6fe6 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CalculateProjectDependencies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CalculateProjectDependencies.cs @@ -26,6 +26,8 @@ public class CalculateProjectDependencies : Task public string NdkVersion { get; set; } + public bool NdkRequired { get; set; } + [Output] public ITaskItem [] Dependencies { get; set; } @@ -57,7 +59,7 @@ public override bool Execute () if (!string.IsNullOrEmpty (ToolsVersion)) { dependencies.Add (CreateAndroidDependency ("tools", ToolsVersion)); } - if (!string.IsNullOrEmpty (NdkVersion)) { + if (!string.IsNullOrEmpty (NdkVersion) && NdkRequired) { dependencies.Add (CreateAndroidDependency ("ndk-bundle", NdkVersion)); } Dependencies = dependencies.ToArray (); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/GetDependenciesTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/GetDependenciesTests.cs index 4157009cab2..07cf16e059f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/GetDependenciesTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/GetDependenciesTests.cs @@ -13,6 +13,46 @@ namespace Xamarin.Android.Build.Tests { [TestFixture] [Parallelizable (ParallelScope.Children)] public class GetDependenciesTest : BaseTest { + + [Test] + public void CheckNdkBundle ([Values(true, false)] bool ndkRequred) + { + var path = Path.Combine ("temp", TestName); + var referencePath = CreateFauxReferencesDirectory (Path.Combine (path, "references"), new ApiInfo [] { + new ApiInfo () { Id = 26, Level = 26, Name = "Oreo", FrameworkVersion = "v8.0", Stable = true }, + }); + MonoAndroidHelper.RefreshSupportedVersions (new string [] { referencePath }); + IBuildEngine engine = new MockBuildEngine (TestContext.Out); + var task = new CalculateProjectDependencies { + BuildEngine = engine + }; + + task.PlatformToolsVersion = "26.0.3"; + task.ToolsVersion = "26.0.1"; + task.NdkVersion = "12.1"; + task.NdkRequired = ndkRequred; + task.BuildToolsVersion = "26.0.1"; + task.TargetFrameworkVersion = "v8.0"; + task.ManifestFile = new TaskItem (Path.Combine (path, "AndroidManifest.xml")); + Assert.IsTrue (task.Execute ()); + Assert.IsNotNull (task.Dependencies); + Assert.AreEqual (5, task.Dependencies.Length); + Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "build-tools;26.0.1" && x.GetMetadata ("Version") == "26.0.1"), + "Dependencies should contains a build-tools version 26.0.1"); + Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "tools" && x.GetMetadata ("Version") == "26.0.1"), + "Dependencies should contains a tools version 26.0.1"); + Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "platforms;android-26" && x.GetMetadata ("Version") == ""), + "Dependencies should contains a platform version android-26"); + Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "platform-tools" && x.GetMetadata ("Version") == "26.0.3"), + "Dependencies should contains a platform-tools version 26.0.3"); + if (ndkRequred) { + Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "ndk-bundle" && x.GetMetadata ("Version") == "12.1"), + "Dependencies should contain a ndk-bundle version 12.1"); + } else { + Assert.IsNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "ndk-bundle"), + "Dependencies should not contain a ndk-bundle item"); + } + } [Test] public void ManifestFileDoesNotExist () @@ -30,6 +70,7 @@ public void ManifestFileDoesNotExist () task.PlatformToolsVersion = "26.0.3"; task.ToolsVersion = "26.0.1"; task.NdkVersion = "12.1"; + task.NdkRequired = true; task.BuildToolsVersion = "26.0.1"; task.TargetFrameworkVersion = "v8.0"; task.ManifestFile = new TaskItem (Path.Combine (path, "AndroidManifest.xml")); @@ -72,6 +113,7 @@ public void ManifestFileExists () task.PlatformToolsVersion = "26.0.3"; task.ToolsVersion = "26.0.1"; task.NdkVersion = "12.1"; + task.NdkRequired = true; task.BuildToolsVersion = "26.0.1"; task.TargetFrameworkVersion = "v8.0"; task.ManifestFile = new TaskItem (manifestFile); diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 2fdca8ab239..9bf713e2e86 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -2773,6 +2773,8 @@ because xbuild doesn't support framework reference assemblies. <_ProjectAndroidManifest>$(ProjectDir)$(AndroidManifest) + <_NdkRequired Condition="'$(BundleAssemblies)' == 'True' Or '$(AotAssemblies)' == 'True'">true + <_NdkRequired Condition="'$(_NdkRequired)' == ''">false From bd16812cbd8b383ed76cb3c8e840375dbe508fe5 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Tue, 13 Feb 2018 14:17:22 +0000 Subject: [PATCH 2/2] Fixed CheckNdkBundle test --- .../Tests/Xamarin.Android.Build.Tests/GetDependenciesTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/GetDependenciesTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/GetDependenciesTests.cs index 07cf16e059f..2f7f98d6acd 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/GetDependenciesTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/GetDependenciesTests.cs @@ -36,7 +36,7 @@ public void CheckNdkBundle ([Values(true, false)] bool ndkRequred) task.ManifestFile = new TaskItem (Path.Combine (path, "AndroidManifest.xml")); Assert.IsTrue (task.Execute ()); Assert.IsNotNull (task.Dependencies); - Assert.AreEqual (5, task.Dependencies.Length); + Assert.AreEqual (ndkRequred ? 5 : 4, task.Dependencies.Length); Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "build-tools;26.0.1" && x.GetMetadata ("Version") == "26.0.1"), "Dependencies should contains a build-tools version 26.0.1"); Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "tools" && x.GetMetadata ("Version") == "26.0.1"),