Uh oh!
There was an error while loading. Please reload this page.
Return a default for unknown API levels - #90
Conversation
jonathanpeppers
commented
Jun 29, 2020
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
e01b9bbComparejonpryor
commented
Jun 30, 2020
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
jonpryor
commented
Jun 30, 2020
The "unrelated test failure" on Windows is because Windows is non-deterministic: the test asserts that given an Android SDK directory varinfo=newAndroidSdkInfo(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. :-( |
jonpryor
commented
Jun 30, 2020
|
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.