TryGetPlatformDirectoryFromApiLevel: fall back to android-{major}.0#320
TryGetPlatformDirectoryFromApiLevel: fall back to android-{major}.0#320jonathanpeppers merged 2 commits intomainfrom
Conversation
…o android-{major}.0
Starting with API 37, Google's SDK Manager installs platforms to
android-37.0 instead of android-37. Add a fallback so that when
the integer-based directory doesn't exist, we also try the .0 suffix.
Fixes: #319
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a compatibility fallback for Android SDK platform directory naming changes introduced with API 37+, preventing XA5207 when the SDK is installed as platforms/android-{major}.0 but the requested platform id is {major}.
Changes:
- Update
AndroidSdkInfo.TryGetPlatformDirectoryFromApiLevelto additionally tryandroid-{id}.0whenidis a pure integer and prior lookups fail. - Add a regression test covering the
android-37→android-37.0fallback behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Xamarin.Android.Tools.AndroidSdk/AndroidSdkInfo.cs | Adds major → major.0 platform directory fallback for integer ids after existing probes fail. |
| tests/Xamarin.Android.Tools.AndroidSdk-Tests/AndroidSdkInfoTests.cs | Adds a new test ensuring TryGetPlatformDirectoryFromApiLevel("37", ...) resolves to platforms/android-37.0 when only that directory exists. |
jonathanpeppers
left a comment
There was a problem hiding this comment.
🤖 AI Review Summary
Verdict: ✅ LGTM
Clean, well-scoped fix for the Google SDK naming change (API 37+). The fallback is correctly placed as a last resort, guarded by int.TryParse to prevent triggering on non-integer IDs like "36.1" or code names. Good test coverage matching existing patterns.
Found 1 suggestion:
- 💡 Consistency:
IsPlatformInstalled(int)doesn’t have the.0fallback — could returnfalsefor API 37+ when onlyandroid-37.0exists (AndroidSdkInfo.cs)
👍 Good defensive coding — the int.TryParse guard prevents double-dotted fallbacks ("37.0" → "37.0.0").
Review generated by android-tools-reviewer from review guidelines by @jonathanpeppers.
IsPlatformInstalled(37) would return false when only android-37.0 exists on disk. Apply the same major.0 fallback for consistency with TryGetPlatformDirectoryFromApiLevel, and add a test assertion. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…back Includes dotnet/android-tools#320 which adds a fallback in TryGetPlatformDirectoryFromApiLevel: when android-{id} doesn't exist and id is an integer, it also tries android-{id}.0. This fixes XA5207 for customers whose SDK Manager installs API 37 to platforms/android-37.0 instead of platforms/android-37. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Starting with API 37, Google's SDK Manager installs platform directories as
android-37.0instead ofandroid-37. BothTryGetPlatformDirectoryFromApiLevelandIsPlatformInstalledonly triedandroid-{major}, so projects targeting these newer API levels would fail with XA5207.This adds a
.0fallback to both methods: when the integer-only directory doesn't exist, also tryandroid-{id}.0.This complements the data-side fix in dotnet/android#11072 (which sets the
Idto"37.0"directly) by providing a safety net when theIdis just"37".Changes
AndroidSdkInfo.TryGetPlatformDirectoryFromApiLevel— After existing lookups fail, tryGetPlatformDirectoryFromId(id + ".0")whenidis an integer.AndroidSdkInfo.IsPlatformInstalled— Apply the same.0fallback so it stays consistent withTryGetPlatformDirectoryFromApiLevel.AndroidSdkInfoTests— New testTryGetPlatformDirectoryFromApiLevel_MajorFallsBackToMajorDotZerocreates onlyandroid-37.0and verifies both APIs find it.Fixes #319