Skip to content

Commit

Permalink
Prevent NRE when Android SDK is not found (#73)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
tondat authored and jonathanpeppers committed Aug 21, 2019
1 parent 9b03310 commit 962c486
Showing 1 changed file with 2 additions and 1 deletion.
Expand Up @@ -241,7 +241,8 @@ protected override IEnumerable<string> GetAllAvailableAndroidNdks ()
string ndk;

var sdks = GetAllAvailableAndroidSdks().ToList();
sdks.Add(AndroidSdkPath);
if (!string.IsNullOrEmpty(AndroidSdkPath))
sdks.Add(AndroidSdkPath);

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

0 comments on commit 962c486

Please sign in to comment.