Skip to content

Commit a963b97

Browse files
dellis1972jonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] fix installing the SDK if one doesn't exist (#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.
1 parent 12dbe95 commit a963b97

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4186,5 +4186,27 @@ public void KotlinServiceLoader ([Values ("apk", "aab")] string packageFormat)
41864186
}
41874187
}
41884188
}
4189+
4190+
[Test]
4191+
public void InstallAndroidDependenciesTest ()
4192+
{
4193+
if (!CommercialBuildAvailable)
4194+
Assert.Ignore ("Not required on Open Source Builds");
4195+
var old = Environment.GetEnvironmentVariable ("ANDROID_SDK_PATH");
4196+
try {
4197+
string sdkPath = Path.Combine (Root, "temp", TestName, "android-sdk");
4198+
Environment.SetEnvironmentVariable ("ANDROID_SDK_PATH", sdkPath);
4199+
var proj = new XamarinAndroidApplicationProject ();
4200+
using (var b = CreateApkBuilder ()) {
4201+
string defaultTarget = b.Target;
4202+
b.Target = "InstallAndroidDependencies";
4203+
Assert.IsTrue (b.Build (proj, parameters: new string [] { "AcceptAndroidSDKLicenses=true" }), "InstallAndroidDependencies should have succeeded.");
4204+
b.Target = defaultTarget;
4205+
Assert.IsTrue (b.Build (proj), "build should have succeeded.");
4206+
}
4207+
} finally {
4208+
Environment.SetEnvironmentVariable ("ANDROID_SDK_PATH", old);
4209+
}
4210+
}
41894211
}
41904212
}

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
781781
<_AndroidAllowMissingSdkTooling Condition=" '$(_AndroidAllowMissingSdkTooling)' == '' ">False</_AndroidAllowMissingSdkTooling>
782782
</PropertyGroup>
783783
<ResolveSdks
784+
ContinueOnError="$(_AndroidAllowMissingSdkTooling)"
784785
AndroidSdkPath="$(AndroidSdkDirectory)"
785786
AndroidNdkPath="$(AndroidNdkDirectory)"
786787
JavaSdkPath="$(JavaSdkDirectory)"
@@ -803,6 +804,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
803804
</ResolveJdkJvmPath>
804805
<ValidateJavaVersion
805806
Condition=" '$(DesignTimeBuild)' != 'True' Or '$(AndroidUseManagedDesignTimeResourceGenerator)' != 'True' "
807+
ContinueOnError="$(_AndroidAllowMissingSdkTooling)"
806808
TargetFrameworkVersion="$(TargetFrameworkVersion)"
807809
AndroidSdkBuildToolsVersion="$(AndroidSdkBuildToolsVersion)"
808810
JavaSdkPath="$(_JavaSdkDirectory)"

0 commit comments

Comments
 (0)