{"record":{"id":"dca8a8f604ce61ae","repo":"pypa/pip","slug":"on-non-android-platforms-the-api-level-and-abi-ar","errorCode":null,"errorMessage":"on non-Android platforms, the api_level and abi arguments are required","messagePattern":"on non-Android platforms, the api_level and abi arguments are required","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/packaging/tags.py","lineNumber":857,"sourceCode":"def android_platforms(\n    api_level: int | None = None, abi: str | None = None\n) -> Iterator[str]:\n    \"\"\"\n    Yields the :attr:`~Tag.platform` tags for Android. If this function is invoked on\n    non-Android platforms, the ``api_level`` and ``abi`` arguments are required.\n\n    :param int api_level: The maximum `API level\n        <https://developer.android.com/tools/releases/platforms>`__ to return. Defaults\n        to the current system's version, as returned by ``platform.android_ver``.\n    :param str abi: The `Android ABI <https://developer.android.com/ndk/guides/abis>`__,\n        e.g. ``arm64_v8a``. Defaults to the current system's ABI , as returned by\n        ``sysconfig.get_platform``. Hyphens and periods will be replaced with\n        underscores.\n\n    .. versionadded:: 25.0\n    \"\"\"\n    if platform.system() != \"Android\" and (api_level is None or abi is None):\n        raise TypeError(\n            \"on non-Android platforms, the api_level and abi arguments are required\"\n        )\n\n    if api_level is None:\n        # Python 3.13 was the first version to return platform.system() == \"Android\",\n        # and also the first version to define platform.android_ver().\n        api_level = platform.android_ver().api_level  # type: ignore[attr-defined]\n\n    if abi is None:\n        abi = sysconfig.get_platform().split(\"-\")[-1]\n    abi = _normalize_string(abi)\n\n    # 16 is the minimum API level known to have enough features to support CPython\n    # without major patching. Yield every API level from the maximum down to the\n    # minimum, inclusive.\n    min_api_level = 16\n    for ver in range(api_level, min_api_level - 1, -1):\n        yield f\"android_{ver}_{abi}\"","sourceCodeStart":839,"sourceCodeEnd":875,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/packaging/tags.py#L839-L875","documentation":"Raised as TypeError by android_platforms (tags.py:856-859) when the function is called on a host whose platform.system() is not 'Android' AND either api_level or abi is None. On a real Android device the values default from platform.android_ver() and sysconfig; on any other OS the caller must supply both explicitly, since there is no Android environment to read them from.","triggerScenarios":"android_platforms() called on Linux/macOS/Windows with no arguments; android_platforms(api_level=30) on macOS (abi missing); android_platforms(abi='arm64_v8a') on Linux (api_level missing); a cross-compilation script invoking it without args on the build host.","commonSituations":"Cross-compiling Android wheels on a non-Android build host; a CI job generating Android platform tags without passing the target API level/ABI; a generic tag-listing tool that calls android_platforms unconditionally.","solutions":["On non-Android hosts, always pass both api_level and abi, e.g. android_platforms(api_level=33, abi='arm64_v8a').","Detect the target before calling: only rely on defaults when platform.system() == 'Android'.","Centralize Android target configuration (API level + ABI) and inject it into the call site.","Catch TypeError and prompt/configure the missing values from your build settings."],"exampleFix":"# before (running on Linux/macOS)\nandroid_platforms()  # TypeError: api_level and abi are required\n\n# after - supply the Android target explicitly\nandroid_platforms(api_level=33, abi='arm64_v8a')","handlingStrategy":"validation","validationCode":"import platform\ndef android_args(api_level=None, abi=None):\n    if platform.system() != 'Android':\n        assert api_level is not None and abi is not None, 'api_level and abi required on non-Android'\n    return api_level, abi","typeGuard":null,"tryCatchPattern":"try:\n    list(android_platforms())\nexcept TypeError:\n    list(android_platforms(api_level=33, abi='arm64_v8a'))","preventionTips":["On non-Android hosts always pass api_level and abi.","Centralize Android target config and inject it.","Detect platform.system() before relying on defaults."],"tags":["packaging","tags","android","cross-compilation","platform"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}