Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] fix installing the SDK if one doesn't e…
Browse files Browse the repository at this point in the history
…xist (#4003)

Fixes #3996

Commit 008ba98 did not go far enough. Both `ValidateJavaVersion` and `ResolveSdks` also needed the same `ContinueOnError` setting. While the commit did allow users to install components which were missing, it did NOT allow users to install the entire SDK. This is because even when calling's the `InstallAndroidDependencies` target the build would still fail with 

```
error XA5300: The Android SDK Directory could not be found. Please set via /p:AndroidSdkDirectory.
```

What we need to do in this case was include the `ContinueOnError` property on `ValidateJavaVersion` and `ResolveSdks`. This allows the build to continue and call the targets to install the required SDK. This is very handy for CI environments as it means we can install the Android SDK from scratch on a clean machine.
  • Loading branch information
dellis1972 authored and jonathanpeppers committed Dec 9, 2019
1 parent e93fe66 commit 68324d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4197,5 +4197,27 @@ public void KotlinServiceLoader ([Values ("apk", "aab")] string packageFormat)
}
}
}

[Test]
public void InstallAndroidDependenciesTest ()
{
if (!CommercialBuildAvailable)
Assert.Ignore ("Not required on Open Source Builds");
var old = Environment.GetEnvironmentVariable ("ANDROID_SDK_PATH");
try {
string sdkPath = Path.Combine (Root, "temp", TestName, "android-sdk");
Environment.SetEnvironmentVariable ("ANDROID_SDK_PATH", sdkPath);
var proj = new XamarinAndroidApplicationProject ();
using (var b = CreateApkBuilder ()) {
string defaultTarget = b.Target;
b.Target = "InstallAndroidDependencies";
Assert.IsTrue (b.Build (proj, parameters: new string [] { "AcceptAndroidSDKLicenses=true" }), "InstallAndroidDependencies should have succeeded.");
b.Target = defaultTarget;
Assert.IsTrue (b.Build (proj), "build should have succeeded.");
}
} finally {
Environment.SetEnvironmentVariable ("ANDROID_SDK_PATH", old);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<_AndroidAllowMissingSdkTooling Condition=" '$(_AndroidAllowMissingSdkTooling)' == '' ">False</_AndroidAllowMissingSdkTooling>
</PropertyGroup>
<ResolveSdks
ContinueOnError="$(_AndroidAllowMissingSdkTooling)"
AndroidSdkPath="$(AndroidSdkDirectory)"
AndroidNdkPath="$(AndroidNdkDirectory)"
JavaSdkPath="$(JavaSdkDirectory)"
Expand All @@ -802,6 +803,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
</ResolveJdkJvmPath>
<ValidateJavaVersion
Condition=" '$(DesignTimeBuild)' != 'True' Or '$(AndroidUseManagedDesignTimeResourceGenerator)' != 'True' "
ContinueOnError="$(_AndroidAllowMissingSdkTooling)"
TargetFrameworkVersion="$(TargetFrameworkVersion)"
AndroidSdkBuildToolsVersion="$(AndroidSdkBuildToolsVersion)"
JavaSdkPath="$(_JavaSdkDirectory)"
Expand Down

0 comments on commit 68324d0

Please sign in to comment.