Skip to content

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

@jonathanpeppers

Description

@jonathanpeppers

Problem

Starting with API 37, Google's SDK Manager installs the platform to platforms/android-37.0 (package name platform-37.0_r01), but TryGetPlatformDirectoryFromApiLevel only tries platforms/android-37 and fails.

This causes XA5207 for customer projects targeting net11.0-android37.

Current behavior

In AndroidSdkInfo.cs:

public string? TryGetPlatformDirectoryFromApiLevel (string idOrApiLevel, AndroidVersions versions)
{
    var id = versions.GetIdFromApiLevel (idOrApiLevel);
    string? dir = GetPlatformDirectoryFromId (id);  // \"platforms/android-37\"

    if (Directory.Exists (dir))
        return dir;

    // Existing fallback: minor -> major (e.g. android-36.1 -> android-36)
    // Guarded to NOT fall back for minor versions (dotnet/android#10720)
    if (Version.TryParse (id, out var version) && version.Minor != 0)
        return null;

    // Integer fallback: also tries GetPlatformDirectory(37) -> \"android-37\" (same thing)
    var level = versions.GetApiLevelFromId (id);
    dir = level.HasValue ? GetPlatformDirectory (level.Value) : null;
    if (dir != null && Directory.Exists (dir))
        return dir;

    return null;  // <-- XA5207!
}

There is no fallback from android-{major} to android-{major}.0.

Proposed fix

When android-{id} doesn't exist and id is a pure integer (major-only), also try android-{id}.0:

// After existing checks fail, try major.0 fallback
if (int.TryParse (id, out _)) {
    dir = GetPlatformDirectoryFromId (id + \".0\");
    if (Directory.Exists (dir))
        return dir;
}

Workaround

dotnet/android#11072 aligns the data so that platformID is \"37.0\" instead of \"37\", which makes the AndroidApiInfo.xml <Id> element 37.0. This means the first lookup will try android-37.0 directly.

However, the android-tools fallback is still valuable as a safety net for cases where the Id is just \"37\".

Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions