Skip to content
Open
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 @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Xml;
using System.Xml.Linq;
using NUnit.Framework;
Expand Down Expand Up @@ -43,11 +44,6 @@ public void InstallAndroidDependenciesTest ([Values ("GoogleV2", "Xamarin")] str
string jdkPath = Path.Combine (Root, "temp", TestName, "android-jdk");
Environment.SetEnvironmentVariable ("TEST_ANDROID_SDK_PATH", sdkPath);
Environment.SetEnvironmentVariable ("TEST_ANDROID_JDK_PATH", jdkPath);
foreach (var path in new [] { sdkPath, jdkPath }) {
if (Directory.Exists (path))
Directory.Delete (path, recursive: true);
Directory.CreateDirectory (path);
}

var proj = new XamarinAndroidApplicationProject {
IsRelease = isRelease,
Expand All @@ -69,7 +65,30 @@ public void InstallAndroidDependenciesTest ([Values ("GoogleV2", "Xamarin")] str
string defaultTarget = b.Target;
b.Target = "InstallAndroidDependencies";
b.BuildLogFile = "install-deps.log";
Assert.IsTrue (b.Build (proj, parameters: buildArgs.ToArray ()), "InstallAndroidDependencies should have succeeded.");

// InstallAndroidDependencies downloads the Android SDK and JDK over the network, which
// can fail intermittently in CI. Retry a few times before giving up, starting from a
// clean SDK/JDK directory each attempt so a partial download does not affect the next.
// See https://github.com/dotnet/android/issues/11973
const int maxInstallAttempts = 3;
bool installSucceeded = false;
for (int attempt = 1; attempt <= maxInstallAttempts; attempt++) {
foreach (var path in new [] { sdkPath, jdkPath }) {
if (Directory.Exists (path))
Directory.Delete (path, recursive: true);
Directory.CreateDirectory (path);
}

if (b.Build (proj, parameters: buildArgs.ToArray ())) {
installSucceeded = true;
break;
}

TestContext.WriteLine ($"InstallAndroidDependencies attempt {attempt} of {maxInstallAttempts} failed. Please check the task output in 'install-deps.log'.");
if (attempt < maxInstallAttempts)
Thread.Sleep (TimeSpan.FromSeconds (10));
}
Assert.IsTrue (installSucceeded, $"InstallAndroidDependencies should have succeeded within {maxInstallAttempts} attempts.");
Comment on lines +69 to +91

// When dependencies can not be resolved/installed a warning will be present in build output:
// Dependency `platform-tools` should have been installed but could not be resolved.
Expand Down
Loading