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..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 @@ -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 (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"), + "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