-
Notifications
You must be signed in to change notification settings - Fork 31
Return a default for unknown API levels #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I think there is an unrelated test failure on Windows: |
In .NET 5, there is a single `AndroidApiInfo.xml` file:
<AndroidApiInfo>
<Id>30</Id>
<Level>30</Level>
<Name>R</Name>
<Version>v11.0</Version>
<Stable>True</Stable>
</AndroidApiInfo>
And so if you call `AndroidVersions.GetApiLevelFromId(29)` you would
always get `null` returned. This is because `KnownVersions` does not
have API 29 or 30 listed.
To fix this and *not* update `KnownVersions`, we can make the various
`GetApiLevelFromId` methods return the incoming API level as a last
resort.
So if 29 comes in, 29 can be returned and assumed to be a valid API
level.
7abeb86 to
e01b9bb
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
The "unrelated test failure" on Windows is because Windows is non-deterministic: the test asserts that given an Android SDK directory var info = new AndroidSdkInfo (logger: null, androidSdkPath: androidSdk);will return The problem is that the If the Registry doesn't have a preferred NDK value, then we hit which means that the order of returned directories is unknowable and may (will?) vary from test run to test run. This is, in short, a highly "unstable" algorithm which won't be consistent from one run to the next. Which explains why it sometimes fails, and sometimes doesn't. :-( |
|
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
In .NET 5, there is a single
AndroidApiInfo.xmlfile:And so if you call
AndroidVersions.GetApiLevelFromId(29)you wouldalways get
nullreturned. This is becauseKnownVersionsdoes nothave API 29 or 30 listed.
To fix this and not update
KnownVersions, we can make the variousGetApiLevelFromIdmethods return the incoming API level as a lastresort.
So if 29 comes in, 29 can be returned and assumed to be a valid API
level.