Skip to content

android_sdk_repository: Support string-based platform API levels (e.g., "36.1") #472

@larryxiao625

Description

@larryxiao625

Summary

The android_sdk_repository rule currently assumes API levels are integers. With the introduction of minor version API levels (e.g., 36.1), the rule fails to correctly parse, compare, and reference these levels, breaking SDK setup for newer Android platform releases.

Problem Description

Android SDK platform directories may now use minor version identifiers (e.g., platforms/android-36.1/). The existing implementation:

  • Defines api_level as an integer-typed config flag (int_flag)
  • Uses %d string formatting for API level references (names, paths, log messages)
  • Selects the default API level via integer comparison

This means any SDK that ships a platform with a minor version (e.g., 36.1) will either be silently ignored or cause a type error, preventing users from building against the latest Android SDK releases.

Expected Behavior

android_sdk_repository should:

  1. Accept API level values in both integer (36) and dot-separated string (36.1) formats.
  2. Correctly identify the latest/default API level across integer and minor-version entries.
  3. Generate valid Bazel target names and file paths using the string representation (e.g., sdk-36.1).

Actual Behavior

Minor-version API levels are not recognized. The rule either skips platforms with minor versions or produces incorrect Bazel targets/paths because it attempts to parse "36.1" as an integer.

Reproduction Steps

  1. Only Install an Android SDK that includes a platforms/android-36.1/ directory.
  2. Configure android_sdk_repository in your WORKSPACE (or MODULE.bazel).
  3. Run any Bazel build targeting @androidsdk//:android or relying on the auto-selected default API level.
  4. Observe that the target does not exist or an error is raised.

Proposed Fix

Migrate API level handling from int to string throughout android_sdk_repository:

  • Replace int_flag with string_flag for the api_level config setting.
  • Use is_android_revision to validate platform directory names.
  • Compare API levels by parsing major/minor/micro components to determine the default.
  • Update all format strings from %d to %s.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions