From fd62d2ff0a9afd3e0d90107a0fc8b6f5bdb31959 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Sat, 10 Feb 2018 15:03:29 +0000 Subject: [PATCH] [Xamarin.Android.Build.Tasks] Add GetAndroidDependencies Target Fixes #1269 This commit adds the `GetAndroidDependencies` target to the `Xamarin.Android.Common.targets`. Its purpose is to examine the various settings in the project and report which android sdk build-tools, platform-tools etc are required. `GetAndroidDependencies` will output an @(AndroidDependency) with Version metadata Valid component names are platform, build-tool, platform-tool and tool. --- .../Tasks/CalculateProjectDependencies.cs | 57 +++++++++++++++++++ .../Xamarin.Android.Build.Tasks.csproj | 1 + .../Xamarin.Android.Common.targets | 19 +++++++ 3 files changed, 77 insertions(+) create mode 100644 src/Xamarin.Android.Build.Tasks/Tasks/CalculateProjectDependencies.cs diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CalculateProjectDependencies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CalculateProjectDependencies.cs new file mode 100644 index 00000000000..d4d447031e0 --- /dev/null +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CalculateProjectDependencies.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using Xamarin.Android.Tools; + +namespace Xamarin.Android.Tasks +{ + public class CalculateProjectDependencies : Task + { + const int DefaultMinSDKVersion = 11; + + [Required] + public string TargetFrameworkVersion { get; set; } + + [Required] + public ITaskItem ManifestFile { get; set; } + + [Required] + public string BuildToolsVersion { get; set; } + + public string PlatformToolsVersion { get; set; } + + public string ToolsVersion { get; set; } + + [Output] + public ITaskItem [] Dependencies { get; set; } + + ITaskItem CreateAndroidDependency (string include, string version) + { + if (string.IsNullOrEmpty (version)) + return new TaskItem (include); + + return new TaskItem (include, new Dictionary { + { "Version", version } + }); + } + + public override bool Execute () + { + var dependencies = new List (); + var targetApiLevel = MonoAndroidHelper.SupportedVersions.GetApiLevelFromFrameworkVersion (TargetFrameworkVersion); + var manifest = AndroidAppManifest.Load (ManifestFile.ItemSpec, MonoAndroidHelper.SupportedVersions); + var manifestApiLevel = manifest.TargetSdkVersion ?? manifest.MinSdkVersion ?? DefaultMinSDKVersion; + dependencies.Add (CreateAndroidDependency ("platform", $"{Math.Max (targetApiLevel.Value, manifestApiLevel)}")); + dependencies.Add (CreateAndroidDependency ("build-tool", BuildToolsVersion)); + if (!string.IsNullOrEmpty (PlatformToolsVersion)) { + dependencies.Add (CreateAndroidDependency ("platform-tool", PlatformToolsVersion)); + } + if (!string.IsNullOrEmpty (ToolsVersion)) { + dependencies.Add (CreateAndroidDependency ("tool", ToolsVersion)); + } + Dependencies = dependencies.ToArray (); + return !Log.HasLoggedErrors; + } + } +} diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj index df83aad5b2a..6c60361d00f 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj @@ -187,6 +187,7 @@ + pdb2mdb\BitAccess.cs diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index f000033f5b6..9a31cf4b1ca 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -32,6 +32,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. + @@ -2767,6 +2768,24 @@ because xbuild doesn't support framework reference assemblies. DependsOnTargets="$(InstallDependsOnTargets)"> + + + + + <_ProjectAndroidManifest>$(ProjectDir)$(AndroidManifest) + + + + + + +