Skip to content

Commit 7852b2d

Browse files
committed
[One .NET] Fix <InstallAndroidDependencies/> target and test
Context: xamarin/android-sdk-installer#450 A fix for the `<InstallAndroidDependencies/>` target has been brought in via the `android-sdk-installer` bump. The `<ResolveAndroidTooling/>` task has been updated to ensure that the `AndroidApilevel` output will be set regardless of whether or not the task fails when detecting Android SDK components. This allows Android SDK provisioning to succeed for One .NET builds when the Android SDK is missing entirely or just missing some components. Previous behavior attempted to determine which `android.jar` to install based on the `$(TargetFrameworkVersion)` of the project, which is not a valid comparison in One .NET projects. The `<InstallAndroidDependencies/>` test previously had issues due to clean up logic in the test framework that partially deleted the newly provisioned Android SDK on a subsequent build. I believe that we've been seeing successful results for this test because the subsequent build in the test would fall back to a different Android SDK that was already on disk. The test has been improved by asserting that the newly installed Android SDK is used during the subsequent build.
1 parent 0907f09 commit 7852b2d

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

.external

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
xamarin/monodroid:master@5784a746112babd9ef801e0a6bc3fe2694bdf64c
1+
xamarin/monodroid:dev/pjc/fix-win-installtask@dd1eeab333de9b590d8bb166d230df7d5bf2be96
22
mono/mono:2020-02@83105ba22461455f4343d6bb14976eba8b0b3f39

src/Xamarin.Android.Build.Tasks/Tasks/ResolveAndroidTooling.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public class ResolveAndroidTooling : AndroidTask
7979

8080
public override bool RunTask ()
8181
{
82+
AndroidApiLevel = GetMaxStableApiLevel ().ToString ();
8283
string toolsZipAlignPath = Path.Combine (AndroidSdkPath, "tools", ZipAlign);
8384
bool findZipAlign = (string.IsNullOrEmpty (ZipAlignPath) || !Directory.Exists (ZipAlignPath)) && !File.Exists (toolsZipAlignPath);
8485

@@ -192,8 +193,7 @@ public override bool RunTask ()
192193

193194
protected virtual bool Validate ()
194195
{
195-
AndroidApiLevel = GetMaxStableApiLevel ().ToString ();
196-
return true;
196+
return !string.IsNullOrEmpty (AndroidApiLevel);
197197
}
198198

199199
protected virtual void LogOutputs ()

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidDependenciesTests.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Xamarin.Android.Build.Tests
77
{
88
[TestFixture]
9-
[Category ("Node-3")]
9+
[Category ("Node-3"), Category ("dotnet")]
1010
[NonParallelizable] // Do not run environment modifying tests in parallel.
1111
public class AndroidDependenciesTests : BaseTest
1212
{
@@ -19,13 +19,19 @@ public void InstallAndroidDependenciesTest ()
1919
try {
2020
string sdkPath = Path.Combine (Root, "temp", TestName, "android-sdk");
2121
Environment.SetEnvironmentVariable ("ANDROID_SDK_PATH", sdkPath);
22+
if (Directory.Exists (sdkPath))
23+
Directory.Delete (sdkPath, true);
24+
Directory.CreateDirectory (sdkPath);
2225
var proj = new XamarinAndroidApplicationProject ();
2326
using (var b = CreateApkBuilder ()) {
27+
b.CleanupAfterSuccessfulBuild = false;
2428
string defaultTarget = b.Target;
2529
b.Target = "InstallAndroidDependencies";
2630
Assert.IsTrue (b.Build (proj, parameters: new string [] { "AcceptAndroidSDKLicenses=true" }), "InstallAndroidDependencies should have succeeded.");
2731
b.Target = defaultTarget;
28-
Assert.IsTrue (b.Build (proj), "build should have succeeded.");
32+
Assert.IsTrue (b.Build (proj, true), "build should have succeeded.");
33+
Assert.IsTrue (b.LastBuildOutput.ContainsText ($"Output Property: _AndroidSdkDirectory={sdkPath}"), "_AndroidSdkDirectory was not set to new SDK path.");
34+
Assert.IsTrue (b.LastBuildOutput.ContainsText ($"JavaPlatformJarPath={sdkPath}"), "JavaPlatformJarPath did not contain new SDK path.");
2935
}
3036
} finally {
3137
Environment.SetEnvironmentVariable ("ANDROID_SDK_PATH", old);

0 commit comments

Comments
 (0)