diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidDependenciesTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidDependenciesTests.cs index dc386e3dfa8..18ed06f2137 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidDependenciesTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidDependenciesTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Xml; using System.Xml.Linq; using NUnit.Framework; using Xamarin.Android.Tools; @@ -31,6 +32,7 @@ public void InstallAndroidDependenciesTest () var proj = new XamarinAndroidApplicationProject { TargetSdkVersion = apiLevel.ToString (), }; + const string ExpectedPlatformToolsVersion = "34.0.1"; using (var b = CreateApkBuilder ()) { b.CleanupAfterSuccessfulBuild = false; string defaultTarget = b.Target; @@ -39,12 +41,26 @@ public void InstallAndroidDependenciesTest () Assert.IsTrue (b.Build (proj, parameters: new string [] { "AcceptAndroidSDKLicenses=true", "AndroidManifestType=GoogleV2", // Need GoogleV2 so we can install API-32 - "AndroidSdkPlatformToolsVersion=34.0.0", + $"AndroidSdkPlatformToolsVersion={ExpectedPlatformToolsVersion}", }), "InstallAndroidDependencies should have succeeded."); b.Target = defaultTarget; b.BuildLogFile = "build.log"; Assert.IsTrue (b.Build (proj, true), "build should have succeeded."); - Assert.IsTrue (b.LastBuildOutput.ContainsText ($"Output Property: _AndroidSdkDirectory={sdkPath}"), $"_AndroidSdkDirectory was not set to new SDK path `{sdkPath}`."); + bool usedNewDir = b.LastBuildOutput.ContainsText ($"Output Property: _AndroidSdkDirectory={sdkPath}"); + if (!usedNewDir) { + // Is this because the platform-tools version changed (again?!) + try { + var currentPlatformToolsVersion = GetCurrentPlatformToolsVersion (); + if (currentPlatformToolsVersion != ExpectedPlatformToolsVersion) { + Assert.Fail ($"_AndroidSdkDirectory not set to new SDK path `{sdkPath}`, *probably* because Google's repository has a newer platform-tools package! " + + $"repository2-3.xml contains platform-tools {currentPlatformToolsVersion}; expected {ExpectedPlatformToolsVersion}!"); + } + } + catch (Exception e) { + TestContext.WriteLine ($"Could not extract platform-tools version from repository2-3.xml: {e}"); + } + } + Assert.IsTrue (usedNewDir, $"_AndroidSdkDirectory was not set to new SDK path `{sdkPath}`."); Assert.IsTrue (b.LastBuildOutput.ContainsText ($"JavaPlatformJarPath={sdkPath}"), $"JavaPlatformJarPath did not contain new SDK path `{sdkPath}`."); } } finally { @@ -52,6 +68,23 @@ public void InstallAndroidDependenciesTest () } } + static string GetCurrentPlatformToolsVersion () + { + var s = new XmlReaderSettings { + XmlResolver = null, + }; + var r = XmlReader.Create ("https://dl-ssl.google.com/android/repository/repository2-3.xml", s); + var d = XDocument.Load (r); + + var platformToolsPackage = d.Root.Elements ("remotePackage") + .Where (e => "platform-tools" == (string) e.Attribute("path")) + .FirstOrDefault (); + + var revision = platformToolsPackage.Element ("revision"); + + return $"{revision.Element ("major")}.{revision.Element ("minor")}.{revision.Element ("micro")}"; + } + [Test] [TestCase ("AotAssemblies", false)] [TestCase ("AndroidEnableProfiledAot", false)]