You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix sort ordering for ndk-bundle, add macOS support (#91)
Fixes: #92
Context: #90 (comment)
The PR builds for #90 encountered an "unrelated test failure"
in `AndroidSdkInfoTests.Ndk_PathInSdk()` on Windows, because Windows
is non-deterministic: the test asserts that given an Android SDK
directory `androidSdk` which contains the file
`{androidSdk}\ndk-bundle\ndk-stack.cmd`, then this:
var info = new AndroidSdkInfo (logger: null, androidSdkPath: androidSdk);
will have `info.AndroidNdkPath`==`{androidSdk}\ndk-bundle`.
Instead, this test would occasionally fail on CI:
Ndk_PathInSdk
AndroidNdkPath not found inside sdk!
Expected string length 71 but was 53. Strings differ at index 3.
Expected: "C:\Users\VssAdministrator\AppData\Local\Temp\tmpAE78.tmp\sdk\..."
But was: "C:\Program Files (x86)\Android\android-sdk\ndk-bundle"
Here, the "preferred"/system-wide NDK is being chosen over the
`{androidSdk}\ndk-bundle` directory that the unit test created.
The wrong directory was chosen for two reasons:
1. `AndroidSdkBase.Initialize()` would use `PreferedAndroidNdkPath`
when `androidNdkPath` was null, *first*, before we checked
`{androidSdk}\ndk-bundle`.
2. If `PreferedAndroidNdkPath` happened to be null, then
`AndroidSdkBase.Initialize()` would try to use
`AllAndroidNdks.FirstOrDefault()` as a default value, also before
checking `{androidSdk}\ndk-bundle`. The problem here is that the
`AllAndrdoidNdks` property uses [`Enumerable.Distinct()`][0], which
returns an *unordered* list of directories.
That the test ever worked at all is a minor miracle.
Additionally, the support for `{androidSdk}\ndk-bundle` was Windows-
specific; it didn't run on macOS.
Update `AndroidSdkInfo` so that `{androidSdk}/ndk-bundle` is supported
on macOS, and that `{androidSdk}/ndk-bundle` is *preferred* when the
`androidNdkPath` parameter is `null`, *before* checking any other
plausible default locations.
This allows the `AndroidSdkInfoTests.Ndk_PathInSdk()` test to run
everywhere, and work reliably.
[0]: https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.distinct?view=netcore-3.1
0 commit comments