@@ -11,7 +11,6 @@ Instead, use one of the tools listed
1111[ here] ( https://docs.python.org/3/using/android.html ) , which will provide a much
1212easier experience.
1313
14-
1514## Prerequisites
1615
1716If you already have an Android SDK installed, export the ` ANDROID_HOME `
2524 ` android-sdk/cmdline-tools/latest ` .
2625* ` export ANDROID_HOME=/path/to/android-sdk `
2726
28- The ` android.py ` script will automatically use the SDK's ` sdkmanager ` to install
27+ The ` Platforms/Android ` script will automatically use the SDK's ` sdkmanager ` to install
2928any packages it needs.
3029
3130The script also requires the following commands to be on the ` PATH ` :
3231
3332* ` curl `
3433* ` java ` (or set the ` JAVA_HOME ` environment variable)
3534
36-
3735## Building
3836
3937Python can be built for Android on any POSIX platform supported by the Android
@@ -43,29 +41,28 @@ First we'll make a "build" Python (for your development machine), then use it to
4341help produce a "host" Python for Android. So make sure you have all the usual
4442tools and libraries needed to build Python for your development machine.
4543
46- The easiest way to do a build is to use the ` android.py ` script. You can either
44+ The easiest way to do a build is to use the ` Platforms/Android ` script. You can either
4745have it perform the entire build process from start to finish in one step, or
4846you can do it in discrete steps that mirror running ` configure ` and ` make ` for
4947each of the two builds of Python you end up producing.
5048
51- The discrete steps for building via ` android.py ` are:
49+ The discrete steps for building via ` Platforms/Android ` are:
5250
5351``` sh
54- ./android.py configure-build
55- ./android.py make-build
56- ./android.py configure-host HOST
57- ./android.py make-host HOST
52+ python3 Platforms/Android configure-build
53+ python3 Platforms/Android make-build
54+ python3 Platforms/Android configure-host HOST
55+ python3 Platforms/Android make-host HOST
5856```
5957
6058` HOST ` identifies which architecture to build. To see the possible values, run
61- ` ./android.py configure-host --help` .
59+ ` python3 Platforms/Android configure-host --help` .
6260
6361To do all steps in a single command, run:
6462
6563``` sh
66- ./android.py build HOST
64+ python3 Platforms/Android build HOST
6765```
68-
6966In the end you should have a build Python in ` cross-build/build ` , and a host
7067Python in ` cross-build/HOST ` .
7168
@@ -75,43 +72,33 @@ call. For example, if you want a pydebug build that also caches the results from
7572` configure ` , you can do:
7673
7774``` sh
78- ./android.py build HOST -- -C --with-pydebug
75+ python3 Platforms/Android build HOST -- -C --with-pydebug
7976```
8077
81-
8278## Packaging
8379
8480After building an architecture as described in the section above, you can
8581package it for release with this command:
8682
8783``` sh
88- ./android.py package HOST
84+ python3 Platforms/Android package HOST
8985```
9086
9187` HOST ` is defined in the section above.
9288
9389This will generate a tarball in ` cross-build/HOST/dist ` , whose structure is
9490similar to the ` Android ` directory of the CPython source tree.
9591
96-
9792## Testing
9893
99- The Python test suite can be run on Linux, macOS, or Windows.
94+ Tests can be run on Linux, macOS, or Windows, using either an Android emulator
95+ or a physical device.
10096
10197On Linux, the emulator needs access to the KVM virtualization interface. This may
10298require adding your user to a group, or changing your udev rules. On GitHub
10399Actions, the test script will do this automatically using the commands shown
104100[ here] ( https://github.blog/changelog/2024-04-02-github-actions-hardware-accelerated-android-virtualization-now-available/ ) .
105101
106- You can run the test suite either:
107-
108- * Within the CPython repository, after doing a build as described above. On
109- Windows, you won't be able to do the build on the same machine, so you'll have
110- to copy the ` cross-build/HOST/prefix ` directory from somewhere else.
111-
112- * Or by taking a release package built using the ` package ` command, extracting
113- it wherever you want, and using its own copy of ` android.py ` .
114-
115102The test script supports the following modes:
116103
117104* In ` --connected ` mode, it runs on a device or emulator you have already
@@ -120,7 +107,7 @@ The test script supports the following modes:
120107 script like this:
121108
122109 ``` sh
123- ./android.py test --connected emulator-5554
110+ python3 Platforms/Android test --connected emulator-5554
124111 ```
125112
126113* In ` --managed ` mode, it uses a temporary headless emulator defined in the
@@ -131,29 +118,55 @@ The test script supports the following modes:
131118 to our minimum and maximum supported Android versions. For example:
132119
133120 ``` sh
134- ./android.py test --managed maxVersion
121+ python3 Platforms/Android test --managed maxVersion
135122 ```
136123
137124By default, the only messages the script will show are Python's own stdout and
138125stderr. Add the ` -v ` option to also show Gradle output, and non-Python logcat
139126messages.
140127
141- Any other arguments on the ` android.py test ` command line will be passed through
142- to ` python -m test ` – use ` -- ` to separate them from android.py's own options.
128+ ### Testing Python
129+
130+ You can run the test suite by doing a build as described above, and then running
131+ ` python3 Platforms/Android test ` . On Windows, you won't be able to do the build
132+ on the same machine, so you'll have to copy the ` cross-build/HOST/prefix ` directory
133+ from somewhere else.
134+
135+ Extra arguments on the ` Platforms/Android test ` command line will be passed through
136+ to ` python -m test ` – use ` -- ` to separate them from ` Platforms/Android ` 's own options.
143137See the [ Python Developer's
144138Guide] ( https://devguide.python.org/testing/run-write-tests/ ) for common options
145139– most of them will work on Android, except for those that involve subprocesses,
146140such as ` -j ` .
147141
148- Every time you run ` android.py test` , changes in pure-Python files in the
142+ Every time you run ` python3 Platforms/Android test` , changes in pure-Python files in the
149143repository's ` Lib ` directory will be picked up immediately. Changes in C files,
150144and architecture-specific files such as sysconfigdata, will not take effect
151- until you re-run ` android.py make-host ` or ` build ` .
145+ until you re-run ` python3 Platforms/Android make-host ` or ` build ` .
146+
147+ ### Testing a third-party package
148+
149+ The ` Platforms/Android ` script is also included as ` android.py ` in the root of a
150+ release package (i.e., the one built using ` Platforms/Android package ` ).
151+
152+ You can use this script to test third-party packages by taking a release
153+ package, extracting it wherever you want, and using the ` android.py ` script to
154+ run the test suite for your third-party package.
155+
156+ Any argument that can be passed to ` python3 Platforms/Android test ` can also be
157+ passed to ` android.py ` . The following options will be of particular use when
158+ configuring the execution of a third-party test suite:
159+
160+ * ` --cwd ` : the directory of content to copy into the testbed app as the working
161+ directory.
162+ * ` --site-packages ` : the directory to copy into the testbed app to use as site
163+ packages.
152164
153- The testbed app can also be used to test third-party packages. For more details,
154- run ` android.py test --help ` , paying attention to the options ` --site-packages ` ,
155- ` --cwd ` , ` -c ` and ` -m ` .
165+ Extra arguments on the ` android.py test ` command line will be passed through to
166+ Python – use ` -- ` to separate them from ` android.py ` 's own options. You must include
167+ either a ` -c ` or ` -m ` argument to specify how the test suite should be started .
156168
169+ For more details, run ` android.py test --help ` .
157170
158171## Using in your own app
159172
0 commit comments