Skip to content

TryGetPlatformDirectoryFromApiLevel: fall back to android-{major}.0#320

Merged
jonathanpeppers merged 2 commits intomainfrom
jonathanpeppers/platform-dir-fallback
Apr 2, 2026
Merged

TryGetPlatformDirectoryFromApiLevel: fall back to android-{major}.0#320
jonathanpeppers merged 2 commits intomainfrom
jonathanpeppers/platform-dir-fallback

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

@jonathanpeppers jonathanpeppers commented Apr 2, 2026

Starting with API 37, Google's SDK Manager installs platform directories as android-37.0 instead of android-37. Both TryGetPlatformDirectoryFromApiLevel and IsPlatformInstalled only tried android-{major}, so projects targeting these newer API levels would fail with XA5207.

This adds a .0 fallback to both methods: when the integer-only directory doesn't exist, also try android-{id}.0.

This complements the data-side fix in dotnet/android#11072 (which sets the Id to "37.0" directly) by providing a safety net when the Id is just "37".

Changes

  • AndroidSdkInfo.TryGetPlatformDirectoryFromApiLevel — After existing lookups fail, try GetPlatformDirectoryFromId(id + ".0") when id is an integer.
  • AndroidSdkInfo.IsPlatformInstalled — Apply the same .0 fallback so it stays consistent with TryGetPlatformDirectoryFromApiLevel.
  • AndroidSdkInfoTests — New test TryGetPlatformDirectoryFromApiLevel_MajorFallsBackToMajorDotZero creates only android-37.0 and verifies both APIs find it.

Fixes #319

…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>
Copilot AI review requested due to automatic review settings April 2, 2026 20:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.TryGetPlatformDirectoryFromApiLevel to additionally try android-{id}.0 when id is a pure integer and prior lookups fail.
  • Add a regression test covering the android-37android-37.0 fallback 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 majormajor.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.

Copy link
Copy Markdown
Member Author

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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 .0 fallback — could return false for API 37+ when only android-37.0 exists (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>
@jonathanpeppers jonathanpeppers enabled auto-merge (squash) April 2, 2026 21:14
@jonathanpeppers jonathanpeppers disabled auto-merge April 2, 2026 21:32
@jonathanpeppers jonathanpeppers merged commit a428178 into main Apr 2, 2026
2 checks passed
@jonathanpeppers jonathanpeppers deleted the jonathanpeppers/platform-dir-fallback branch April 2, 2026 21:32
jonathanpeppers added a commit to dotnet/android that referenced this pull request Apr 2, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TryGetPlatformDirectoryFromApiLevel should fall back from android-{major} to android-{major}.0

2 participants