forked from dotnet/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Build.Tasks] Add GetAndroidDependencies Target
Fixes dotnet#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.
- Loading branch information
1 parent
7c31899
commit fd62d2f
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/Xamarin.Android.Build.Tasks/Tasks/CalculateProjectDependencies.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string, string> { | ||
{ "Version", version } | ||
}); | ||
} | ||
|
||
public override bool Execute () | ||
{ | ||
var dependencies = new List<ITaskItem> (); | ||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters