11# Python for Android
22
3- These instructions are only needed if you're planning to compile Python for
4- Android yourself. Most users should * not* need to do this. Instead, use one of
5- the tools listed in ` Doc/using/android.rst ` , which will provide a much easier
6- experience.
3+ If you obtained this README as part of a release package, then the only
4+ applicable sections are "Prerequisites", "Testing", and "Using in your own app".
75
6+ If you obtained this README as part of the CPython source tree, then you can
7+ also follow the other sections to compile Python for Android yourself.
8+
9+ However, most app developers should not need to do any of these things manually.
10+ Instead, use one of the tools listed
11+ [ here] ( https://docs.python.org/3/using/android.html ) , which will provide a much
12+ easier experience.
813
9- ## Prerequisites
1014
11- First, make sure you have all the usual tools and libraries needed to build
12- Python for your development machine.
15+ ## Prerequisites
1316
14- Second, you'll need an Android SDK. If you already have the SDK installed,
15- export the ` ANDROID_HOME ` environment variable to point at its location.
16- Otherwise, here's how to install it:
17+ If you already have an Android SDK installed, export the ` ANDROID_HOME `
18+ environment variable to point at its location. Otherwise, here's how to install
19+ it:
1720
1821* Download the "Command line tools" from < https://developer.android.com/studio > .
1922* Create a directory ` android-sdk/cmdline-tools ` , and unzip the command line
@@ -27,15 +30,16 @@ The `android.py` script also requires the following commands to be on the `PATH`
2730* ` curl `
2831* ` java ` (or set the ` JAVA_HOME ` environment variable)
2932* ` tar `
30- * ` unzip `
3133
3234
3335## Building
3436
3537Python can be built for Android on any POSIX platform supported by the Android
36- development tools, which currently means Linux or macOS. This involves doing a
37- cross-build where you use a "build" Python (for your development machine) to
38- help produce a "host" Python for Android.
38+ development tools, which currently means Linux or macOS.
39+
40+ First we'll make a "build" Python (for your development machine), then use it to
41+ help produce a "host" Python for Android. So make sure you have all the usual
42+ tools and libraries needed to build Python for your development machine.
3943
4044The easiest way to do a build is to use the ` android.py ` script. You can either
4145have it perform the entire build process from start to finish in one step, or
@@ -60,8 +64,8 @@ To do all steps in a single command, run:
6064./android.py build HOST
6165```
6266
63- In the end you should have a build Python in ` cross-build/build ` , and an Android
64- build in ` cross-build/HOST ` .
67+ In the end you should have a build Python in ` cross-build/build ` , and a host
68+ Python in ` cross-build/HOST ` .
6569
6670You can use ` -- ` as a separator for any of the ` configure ` -related commands –
6771including ` build ` itself – to pass arguments to the underlying ` configure `
@@ -73,14 +77,27 @@ call. For example, if you want a pydebug build that also caches the results from
7377```
7478
7579
80+ ## Packaging
81+
82+ After building an architecture as described in the section above, you can
83+ package it for release with this command:
84+
85+ ``` sh
86+ ./android.py package HOST
87+ ```
88+
89+ ` HOST ` is defined in the section above.
90+
91+ This will generate a tarball in ` cross-build/HOST/dist ` , whose structure is
92+ similar to the ` Android ` directory of the CPython source tree.
93+
94+
7695## Testing
7796
78- The test suite can be run on Linux, macOS, or Windows:
97+ The Python test suite can be run on Linux, macOS, or Windows:
7998
8099* On Linux, the emulator needs access to the KVM virtualization interface, and
81100 a DISPLAY environment variable pointing at an X server.
82- * On Windows, you won't be able to do the build on the same machine, so you'll
83- have to copy the ` cross-build/HOST ` directory from somewhere else.
84101
85102The test suite can usually be run on a device with 2 GB of RAM, but this is
86103borderline, so you may need to increase it to 4 GB. As of Android
@@ -90,9 +107,16 @@ and find `hw.ramSize` in both config.ini and hardware-qemu.ini. Either set these
90107manually to the same value, or use the Android Studio Device Manager, which will
91108update both files.
92109
93- Before running the test suite, follow the instructions in the previous section
94- to build the architecture you want to test. Then run the test script in one of
95- the following modes:
110+ You can run the test suite either:
111+
112+ * Within the CPython repository, after doing a build as described above. On
113+ Windows, you won't be able to do the build on the same machine, so you'll have
114+ to copy the ` cross-build/HOST/prefix ` directory from somewhere else.
115+
116+ * Or by taking a release package built using the ` package ` command, extracting
117+ it wherever you want, and using its own copy of ` android.py ` .
118+
119+ The test script supports the following modes:
96120
97121* In ` --connected ` mode, it runs on a device or emulator you have already
98122 connected to the build machine. List the available devices with
@@ -133,4 +157,4 @@ until you re-run `android.py make-host` or `build`.
133157
134158## Using in your own app
135159
136- See ` Doc/ using/android.rst ` .
160+ See https://docs.python.org/3/ using/android.html .
0 commit comments