Skip to content

Commit 962c486

Browse files
tondatjonathanpeppers
authored andcommitted
Prevent NRE when Android SDK is not found (#73)
Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/938504 In dc00a39, we added a search path for the NDK which is now *inside* the Android SDK. However, this change could produce a `NullReferenceException` if the Android SDK is not found. In cases where an Android SDK is not found, and the `AndroidSdkPath` property is null, we still go on to use the null property when locating the Android NDK: var sdks = GetAllAvailableAndroidSdks().ToList(); sdks.Add(AndroidSdkPath); foreach(var sdk in sdks.Distinct()) if (Directory.Exists(ndk = Path.Combine(sdk, "ndk-bundle"))) The `Path.Combine` will throw if you pass in a null. This fix doesn't *solve* the exception, as you will still get an `InvalidOperationException` for the missing Android SDK. However, that is certainly a more descriptive error message than a `NullReferenceException`.
1 parent 9b03310 commit 962c486

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkWindows.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ protected override IEnumerable<string> GetAllAvailableAndroidNdks ()
241241
string ndk;
242242

243243
var sdks = GetAllAvailableAndroidSdks().ToList();
244-
sdks.Add(AndroidSdkPath);
244+
if (!string.IsNullOrEmpty(AndroidSdkPath))
245+
sdks.Add(AndroidSdkPath);
245246

246247
foreach(var sdk in sdks.Distinct())
247248
if (Directory.Exists(ndk = Path.Combine(sdk, "ndk-bundle")))

0 commit comments

Comments
 (0)