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) + + + + + + +