Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public class ResolveAndroidTooling : AndroidTask

public override bool RunTask ()
{
AndroidApiLevel = GetMaxStableApiLevel ().ToString ();

string toolsZipAlignPath = Path.Combine (AndroidSdkPath, "tools", ZipAlign);
bool findZipAlign = (string.IsNullOrEmpty (ZipAlignPath) || !Directory.Exists (ZipAlignPath)) && !File.Exists (toolsZipAlignPath);

Expand Down Expand Up @@ -190,11 +192,7 @@ public override bool RunTask ()
return !Log.HasLoggedErrors;
}

protected virtual bool Validate ()
{
AndroidApiLevel = GetMaxStableApiLevel ().ToString ();
return true;
}
protected virtual bool Validate () => !string.IsNullOrEmpty (AndroidApiLevel);

protected virtual void LogOutputs ()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using NUnit.Framework;
using Xamarin.ProjectTools;

namespace Xamarin.Android.Build.Tests
{
[TestFixture]
[Category ("Node-3")]
[NonParallelizable] // Do not run environment modifying tests in parallel.
[Category ("Node-3"), Category ("dotnet")]
[Parallelizable (ParallelScope.Children)]
public class AndroidDependenciesTests : BaseTest
{
[Test]
[NonParallelizable] // Do not run environment modifying tests in parallel.
public void InstallAndroidDependenciesTest ()
{
if (!CommercialBuildAvailable)
Assert.Ignore ("Not required on Open Source Builds");
AssertCommercialBuild ();
if (IsWindows) {
// TODO: we need: https://github.com/xamarin/android-sdk-installer/pull/450
Assert.Ignore ("InstallAndroidDependencies currently fails on Windows");
}
var old = Environment.GetEnvironmentVariable ("ANDROID_SDK_PATH");
try {
string sdkPath = Path.Combine (Root, "temp", TestName, "android-sdk");
Expand All @@ -31,5 +38,108 @@ public void InstallAndroidDependenciesTest ()
Environment.SetEnvironmentVariable ("ANDROID_SDK_PATH", old);
}
}

[Test]
[TestCase ("AotAssemblies", false)]
[TestCase ("AndroidEnableProfiledAot", false)]
[TestCase ("EnableLLVM", true)]
[TestCase ("BundleAssemblies", true)]
public void GetDependencyNdkRequiredConditions (string property, bool ndkRequired)
{
var proj = new XamarinAndroidApplicationProject ();
proj.AotAssemblies = true;
proj.SetProperty (property, "true");
using (var builder = CreateApkBuilder ()) {
builder.Target = "GetAndroidDependencies";
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
IEnumerable<string> taskOutput = builder.LastBuildOutput
.Select (x => x.Trim ())
.SkipWhile (x => !x.StartsWith ("Task \"CalculateProjectDependencies\""))
.SkipWhile (x => !x.StartsWith ("Output Item(s):"))
.TakeWhile (x => !x.StartsWith ("Done executing task \"CalculateProjectDependencies\""));
if (ndkRequired)
StringAssertEx.Contains ("ndk-bundle", taskOutput, "ndk-bundle should be a dependency.");
else
StringAssertEx.DoesNotContain ("ndk-bundle", taskOutput, "ndk-bundle should not be a dependency.");
}
}

[Test]
public void GetDependencyWhenBuildToolsAreMissingTest ()
{
var apis = new ApiInfo [] {
};
var path = Path.Combine ("temp", TestName);
var androidSdkPath = CreateFauxAndroidSdkDirectory (Path.Combine (path, "android-sdk"),
null, apis);
var referencesPath = CreateFauxReferencesDirectory (Path.Combine (path, "xbuild-frameworks"), apis);
var proj = new XamarinAndroidApplicationProject () {
IsRelease = true,
TargetFrameworkVersion = "v8.0",
UseLatestPlatformSdk = false,
};
var parameters = new string [] {
$"TargetFrameworkRootPath={referencesPath}",
$"AndroidSdkDirectory={androidSdkPath}",
};
string buildToolsVersion = GetExpectedBuildToolsVersion ();
using (var builder = CreateApkBuilder (Path.Combine (path, proj.ProjectName), cleanupAfterSuccessfulBuild: false, cleanupOnDispose: false)) {
builder.ThrowOnBuildFailure = false;
builder.Target = "GetAndroidDependencies";
Assert.True (builder.Build (proj, parameters: parameters),
string.Format ("First Build should have succeeded"));
int apiLevel = Builder.UseDotNet ? builder.GetMaxInstalledPlatform () : 26;
StringAssertEx.Contains ($"platforms/android-{apiLevel}", builder.LastBuildOutput, $"platforms/android-{apiLevel} should be a dependency.");
StringAssertEx.Contains ($"build-tools/{buildToolsVersion}", builder.LastBuildOutput, $"build-tools/{buildToolsVersion} should be a dependency.");
StringAssertEx.Contains ("platform-tools", builder.LastBuildOutput, "platform-tools should be a dependency.");
}
}

[Test]
public void GetDependencyWhenSDKIsMissingTest ([Values (true, false)] bool createSdkDirectory)
{
var apis = new ApiInfo [] {
};
var path = Path.Combine ("temp", TestName);
var androidSdkPath = Path.Combine (path, "android-sdk");
if (createSdkDirectory)
Directory.CreateDirectory (androidSdkPath);
else if (Directory.Exists (androidSdkPath))
Directory.Delete (androidSdkPath, recursive: true);
var referencesPath = CreateFauxReferencesDirectory (Path.Combine (path, "xbuild-frameworks"), apis);
var proj = new XamarinAndroidApplicationProject () {
IsRelease = true,
TargetFrameworkVersion = "v8.0",
UseLatestPlatformSdk = false,
};
var parameters = new string [] {
$"TargetFrameworkRootPath={referencesPath}",
$"AndroidSdkDirectory={androidSdkPath}",
};

string buildToolsVersion = GetExpectedBuildToolsVersion ();
using (var builder = CreateApkBuilder (Path.Combine (path, proj.ProjectName), cleanupAfterSuccessfulBuild: false, cleanupOnDispose: false)) {
builder.ThrowOnBuildFailure = false;
builder.Target = "GetAndroidDependencies";
Assert.True (builder.Build (proj, parameters: parameters),
string.Format ("First Build should have succeeded"));
int apiLevel = Builder.UseDotNet ? builder.GetMaxInstalledPlatform () : 26;
StringAssertEx.Contains ($"platforms/android-{apiLevel}", builder.LastBuildOutput, $"platforms/android-{apiLevel} should be a dependency.");
StringAssertEx.Contains ($"build-tools/{buildToolsVersion}", builder.LastBuildOutput, $"build-tools/{buildToolsVersion} should be a dependency.");
StringAssertEx.Contains ("platform-tools", builder.LastBuildOutput, "platform-tools should be a dependency.");
}
}

static readonly XNamespace MSBuildXmlns = "http://schemas.microsoft.com/developer/msbuild/2003";

static string GetExpectedBuildToolsVersion ()
{
var propsPath = Path.Combine (XABuildPaths.TopDirectory, "src", "Xamarin.Android.Build.Tasks", "Xamarin.Android.Common.props.in");
var props = XElement.Load (propsPath);
var AndroidSdkBuildToolsVersion = props.Elements (MSBuildXmlns + "PropertyGroup")
.Elements (MSBuildXmlns + "AndroidSdkBuildToolsVersion")
.FirstOrDefault ();
return AndroidSdkBuildToolsVersion?.Value?.Trim ();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3200,108 +3200,6 @@ public void IfAndroidJarDoesNotExistThrowXA5207 ()
Directory.Delete (AndroidSdkDirectory, recursive: true);
}

[Test]
[TestCase ("AotAssemblies", false)]
[TestCase ("AndroidEnableProfiledAot", false)]
[TestCase ("EnableLLVM", true)]
[TestCase ("BundleAssemblies", true)]
public void GetDependencyNdkRequiredConditions (string property, bool ndkRequired)
{
var proj = new XamarinAndroidApplicationProject ();
proj.AotAssemblies = true;
proj.SetProperty (property, "true");
using (var builder = CreateApkBuilder ()) {
builder.Target = "GetAndroidDependencies";
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
IEnumerable<string> taskOutput = builder.LastBuildOutput
.SkipWhile (x => !x.StartsWith ("Task \"CalculateProjectDependencies\""))
.SkipWhile (x => !x.StartsWith (" Output Item(s):"))
.TakeWhile (x => !x.StartsWith ("Done executing task \"CalculateProjectDependencies\""));
if (ndkRequired)
StringAssertEx.Contains ("ndk-bundle", taskOutput, "ndk-bundle should be a dependency.");
else
StringAssertEx.DoesNotContain ("ndk-bundle", taskOutput, "ndk-bundle should not be a dependency.");
}
}

[Test]
public void GetDependencyWhenBuildToolsAreMissingTest ()
{
var apis = new ApiInfo [] {
};
var path = Path.Combine ("temp", TestName);
var androidSdkPath = CreateFauxAndroidSdkDirectory (Path.Combine (path, "android-sdk"),
null, apis);
var referencesPath = CreateFauxReferencesDirectory (Path.Combine (path, "xbuild-frameworks"), apis);
var proj = new XamarinAndroidApplicationProject () {
IsRelease = true,
TargetFrameworkVersion = "v8.0",
UseLatestPlatformSdk = false,
};
var parameters = new string [] {
$"TargetFrameworkRootPath={referencesPath}",
$"AndroidSdkDirectory={androidSdkPath}",
};
string buildToolsVersion = GetExpectedBuildToolsVersion ();
using (var builder = CreateApkBuilder (Path.Combine (path, proj.ProjectName), cleanupAfterSuccessfulBuild: false, cleanupOnDispose: false)) {
builder.ThrowOnBuildFailure = false;
builder.Target = "GetAndroidDependencies";
Assert.True (builder.Build (proj, parameters: parameters),
string.Format ("First Build should have succeeded"));
StringAssertEx.Contains ("platforms/android-26", builder.LastBuildOutput, "platforms/android-26 should be a dependency.");
StringAssertEx.Contains ($"build-tools/{buildToolsVersion}", builder.LastBuildOutput, $"build-tools/{buildToolsVersion} should be a dependency.");
StringAssertEx.Contains ("platform-tools", builder.LastBuildOutput, "platform-tools should be a dependency.");
}
}

[Test]
[Category ("dotnet")]
public void GetDependencyWhenSDKIsMissingTest ([Values (true, false)] bool createSdkDirectory)
{
var apis = new ApiInfo [] {
};
var path = Path.Combine ("temp", TestName);
var androidSdkPath = Path.Combine (path, "android-sdk");
if (createSdkDirectory)
Directory.CreateDirectory (androidSdkPath);
else if (Directory.Exists (androidSdkPath))
Directory.Delete (androidSdkPath, recursive: true);
var referencesPath = CreateFauxReferencesDirectory (Path.Combine (path, "xbuild-frameworks"), apis);
var proj = new XamarinAndroidApplicationProject () {
IsRelease = true,
TargetFrameworkVersion = "v8.0",
UseLatestPlatformSdk = false,
};
var parameters = new string [] {
$"TargetFrameworkRootPath={referencesPath}",
$"AndroidSdkDirectory={androidSdkPath}",
};

string buildToolsVersion = GetExpectedBuildToolsVersion ();
using (var builder = CreateApkBuilder (Path.Combine (path, proj.ProjectName), cleanupAfterSuccessfulBuild: false, cleanupOnDispose: false)) {
builder.ThrowOnBuildFailure = false;
builder.Target = "GetAndroidDependencies";
Assert.True (builder.Build (proj, parameters: parameters),
string.Format ("First Build should have succeeded"));
int apiLevel = Builder.UseDotNet ? builder.GetMaxInstalledPlatform () : 26;
StringAssertEx.Contains ($"platforms/android-{apiLevel}", builder.LastBuildOutput, $"platforms/android-{apiLevel} should be a dependency.");
StringAssertEx.Contains ($"build-tools/{buildToolsVersion}", builder.LastBuildOutput, $"build-tools/{buildToolsVersion} should be a dependency.");
StringAssertEx.Contains ("platform-tools", builder.LastBuildOutput, "platform-tools should be a dependency.");
}
}

static readonly XNamespace MSBuildXmlns = "http://schemas.microsoft.com/developer/msbuild/2003";

static string GetExpectedBuildToolsVersion ()
{
var propsPath = Path.Combine (XABuildPaths.TopDirectory, "src", "Xamarin.Android.Build.Tasks", "Xamarin.Android.Common.props.in");
var props = XElement.Load (propsPath);
var AndroidSdkBuildToolsVersion = props.Elements (MSBuildXmlns+"PropertyGroup")
.Elements (MSBuildXmlns+"AndroidSdkBuildToolsVersion")
.FirstOrDefault ();
return AndroidSdkBuildToolsVersion?.Value?.Trim ();
}

[Test]
public void ValidateUseLatestAndroid ()
{
Expand Down