Skip to content

Add Android support for Python 3.11 and 3.12 - #108

Open
kattni wants to merge 2 commits into
beeware:mainfrom
kattni:py311-312-support
Open

kattni wants to merge 2 commits into
beeware:mainfrom
kattni:py311-312-support

Conversation

@kattni

@kattni kattni commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Adds Android support for Python 3.11 and 3.12.

There are no official Android builds of Python 3.11 or 3.12. xvenv now uses the builds that Chaquopy publishes on Maven Central for these versions (com.chaquo.python:target, 3.11.17-0 and 3.12.15-0). Each one comes as a set of zip files (one per ABI, plus the standard library), not as a single archive. xvenv reassembles them into the layout of an official Android release package:

  • headers go into prefix/include, shared libraries into prefix/lib, and the standard library and extension modules into prefix/lib/pythonX.Y;
  • _sysconfigdata__android_<triplet>.py is generated from Chaquopy's shared _sysconfigdata__linux_.py, with MULTIARCH, HOST_GNU_TYPE and the compiler triplet adjusted for the target architecture;
  • CPython's android.py and android-env.sh are added, with the API level taken from the Chaquopy build (24).

Assembly happens in a temporary directory inside the cache, so a failure doesn't leave a partial build behind. To support this, downloading is now a per-platform fetch_archive() built on shared download()/download_archive() helpers in xvenv.fetch.

xpython now ships its own copy of CPython's Android testbed (android.py, android-env.sh and testbed/, from Platforms/Android on CPython main) as a resource. The Android testbed is cloned from that copy instead of from the Python build. Provenance is recorded in src/xpython/resources/android/README.md. Python versions before 3.13 don't redirect sys.stdout/sys.stderr to logcat, so for those the testbed also gets a copy of 3.13's _android_support module, plus a .pth hook that installs the redirection at startup. Without it, the testbed driver would never show any output.

Other changes:

  • The cross-env template defines platform.AndroidVer on Python < 3.13.
  • android.py test is now run through sys.executable, because installing from a wheel doesn't keep the script's executable bit.
  • The vendored files are excluded from pre-commit, ruff and rumdl, so they stay identical to their source.
  • The CI unit-test matrix now runs 3.11 and 3.12 on every runner, and the live tests no longer skip Android on 3.11/3.12.

Testing: the unit tests pass on 3.11, 3.12 and 3.14, and the live xvenv tests (including Android aarch64/x86_64) pass locally on 3.11, 3.12 and 3.14. I haven't been able to run the live xbuild/xpython Android tests locally (no Android SDK), so CI on Linux will be the first run of the testbed on an emulator with 3.11/3.12.

PR Checklist:

  • I will abide by the BeeWare Code of Conduct
  • I have read and have followed the CONTRIBUTING.md file
  • This PR was generated or assisted using an AI tool

Assisted-by: Claude Code (Claude Opus 5.5)

There are no official Android builds of Python 3.11 or 3.12, so xvenv
downloads Chaquopy's builds of these versions, and assembles them into
the layout of an official Android release package.

xpython now uses its own copy of CPython's Android testbed (from the
main branch), rather than the copy included in the Android Python
build. For Python versions that don't redirect stdout and stderr to the
Android log, a backport of Python 3.13's redirection is added to the
testbed.
@kattni
kattni marked this pull request as ready for review October 18, 2026 01:43
@mhsmith

mhsmith commented Oct 19, 2026

Copy link
Copy Markdown
Member

Based on my so-far limited knowledge of xbuild, this makes sense in principle. But what is its use case? The cross-venv approach isn't viable for Briefcase or Chaquopy, because it doesn't work on Windows (chaquo/chaquopy#981 (comment)). And these Python versions aren't supported on Android by cibuildwheel either. That could potentially be changed, but it doesn't seem worth the effort for Python versions that have less than 2 years of lifetime remaining.

@kattni

kattni commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@mhsmith The use case is exploring using Briefcase for environment management and installation, which then requires the use of xbuild, but opens up conda and uv for environment management. xvenv will create valid virtual environments under windows, it can't be used to build wheels, but that's always been the case. This links with beeware/briefcase-android-gradle-template#134 and beeware/briefcase#3099 to make this happen.

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.

2 participants