1
1
# Python for Android
2
2
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".
7
5
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.
8
13
9
- ## Prerequisites
10
14
11
- First, make sure you have all the usual tools and libraries needed to build
12
- Python for your development machine.
15
+ ## Prerequisites
13
16
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:
17
20
18
21
* Download the "Command line tools" from < https://developer.android.com/studio > .
19
22
* 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`
27
30
* ` curl `
28
31
* ` java ` (or set the ` JAVA_HOME ` environment variable)
29
32
* ` tar `
30
- * ` unzip `
31
33
32
34
33
35
## Building
34
36
35
37
Python 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.
39
43
40
44
The easiest way to do a build is to use the ` android.py ` script. You can either
41
45
have 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:
60
64
./android.py build HOST
61
65
```
62
66
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 ` .
65
69
66
70
You can use ` -- ` as a separator for any of the ` configure ` -related commands –
67
71
including ` 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
73
77
```
74
78
75
79
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
+
76
95
## Testing
77
96
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:
79
98
80
99
* On Linux, the emulator needs access to the KVM virtualization interface, and
81
100
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.
84
101
85
102
The test suite can usually be run on a device with 2 GB of RAM, but this is
86
103
borderline, 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
90
107
manually to the same value, or use the Android Studio Device Manager, which will
91
108
update both files.
92
109
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:
96
120
97
121
* In ` --connected ` mode, it runs on a device or emulator you have already
98
122
connected to the build machine. List the available devices with
@@ -133,4 +157,4 @@ until you re-run `android.py make-host` or `build`.
133
157
134
158
## Using in your own app
135
159
136
- See ` Doc/ using/android.rst ` .
160
+ See https://docs.python.org/3/ using/android.html .
0 commit comments