forked from kivy/python-for-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildoptions.rst
More file actions
253 lines (206 loc) · 10.8 KB
/
buildoptions.rst
File metadata and controls
253 lines (206 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
Build options
=============
This page contains instructions for using different build options.
Python versions
---------------
python2
~~~~~~~
Select this by adding it in your requirements, e.g. ``--requirements=python2``.
This option builds Python 2.7.2 for your selected Android
architecture. There are no special requirements, all the building is
done locally.
python3
~~~~~~~
Python3 is supported in two ways. The default method uses CPython 3.7+
and works with any recent version of the Android NDK.
Select Python 3 by adding it to your requirements,
e.g. ``--requirements=python3``.
.. note:: ctypes is not included automatically, if you would like to use it
then add libffi to your requirements,
e.g. ``--requirements=kivy,libffi,python3``.
CrystaX python3
###############
.. warning:: python-for-android originally supported Python 3 using the CrystaX
NDK. This support is now being phased out as CrystaX is no longer
actively developed.
.. note:: You must manually download the `CrystaX NDK
<https://www.crystax.net/android/ndk>`__ and tell
python-for-android to use it with ``--ndk-dir /path/to/NDK``.
Select this by adding the ``python3crystax`` recipe to your
requirements, e.g. ``--requirements=python3crystax``.
This uses the prebuilt Python from the `CrystaX NDK
<https://www.crystax.net/android/ndk>`__, a drop-in replacement for
Google's official NDK which includes many improvements. You
*must* use the CrystaX NDK 10.3.0 or higher when building with
python3. You can get it `here
<https://www.crystax.net/en/download>`__.
.. _bootstrap_build_options:
Bootstrap options
-----------------
python-for-android supports multiple app backends with different types
of interface. These are called *bootstraps*.
Currently the following bootstraps are supported, but we hope that it
should be easy to add others if your project has different
requirements. `Let us know
<https://groups.google.com/forum/#!forum/python-android>`__ if you'd
like help adding a new one.
sdl2
~~~~
Use this with ``--bootstrap=sdl2``, or just include the
``sdl2`` recipe, e.g. ``--requirements=sdl2,python2``.
SDL2 is a popular cross-platform depelopment library, particularly for
games. It has its own Android project support, which
python-for-android uses as a bootstrap, and to which it adds the
Python build and JNI code to start it.
From the point of view of a Python program, SDL2 should behave as
normal. For instance, you can build apps with Kivy or PySDL2
and have them work with this bootstrap. It should also be possible to
use e.g. pygame_sdl2, but this would need a build recipe and doesn't
yet have one.
Build options
%%%%%%%%%%%%%
The sdl2 bootstrap supports the following additional command line
options (this list may not be exhaustive):
- ``--private``: The directory containing your project files.
- ``--package``: The Java package name for your project. e.g. ``org.example.yourapp``.
- ``--name``: The app name.
- ``--version``: The version number.
- ``--orientation``: Usually one of ``portait``, ``landscape``,
``sensor`` to automatically rotate according to the device
orientation, or ``user`` to do the same but obeying the user's
settings. The full list of valid options is given under
``android:screenOrientation`` in the `Android documentation
<https://developer.android.com/guide/topics/manifest/activity-element.html>`__.
- ``--icon``: A path to the png file to use as the application icon.
- ``--permission``: A permission name for the app,
e.g. ``--permission VIBRATE``. For multiple permissions, add
multiple ``--permission`` arguments.
- ``--meta-data``: Custom key=value pairs to add in the application metadata.
- ``--presplash``: A path to the image file to use as a screen while
the application is loading.
- ``--presplash-color``: The presplash screen background color, of the
form ``#RRGGBB`` or a color name ``red``, ``green``, ``blue`` etc.
- ``--wakelock``: If the argument is included, the application will
prevent the device from sleeping.
- ``--window``: If the argument is included, the application will not
cover the Android status bar.
- ``--blacklist``: The path to a file containing blacklisted patterns
that will be excluded from the final APK. Defaults to ``./blacklist.txt``.
- ``--whitelist``: The path to a file containing whitelisted patterns
that will be included in the APK even if also blacklisted.
- ``--add-jar``: The path to a .jar file to include in the APK. To
include multiple jar files, pass this argument multiple times.
- ``--intent-filters``: A file path containing intent filter xml to be
included in AndroidManifest.xml.
- ``--service``: A service name and the Python script it should
run. See :ref:`arbitrary_scripts_services`.
- ``--add-source``: Add a source directory to the app's Java code.
- ``--no-compile-pyo``: Do not optimise .py files to .pyo.
webview
~~~~~~~
You can use this with ``--bootstrap=webview``, or include the
``webviewjni`` recipe, e.g. ``--requirements=webviewjni,python2``.
The webview bootstrap gui is, per the name, a WebView displaying a
webpage, but this page is hosted on the device via a Python
webserver. For instance, your Python code can start a Flask
application, and your app will display and allow the user to navigate
this website.
.. note:: Your Flask script must start the webserver *without*
:code:``debug=True``. Debug mode doesn't seem to work on
Android due to use of a subprocess.
This bootstrap will automatically try to load a website on port 5000
(the default for Flask), or you can specify a different option with
the `--port` command line option. If the webserver is not immediately
present (e.g. during the short Python loading time when first
started), it will instead display a loading screen until the server is
ready.
- ``--private``: The directory containing your project files.
- ``--package``: The Java package name for your project. e.g. ``org.example.yourapp``.
- ``--name``: The app name.
- ``--version``: The version number.
- ``--orientation``: Usually one of ``portait``, ``landscape``,
``sensor`` to automatically rotate according to the device
orientation, or ``user`` to do the same but obeying the user's
settings. The full list of valid options is given under
``android:screenOrientation`` in the `Android documentation
<https://developer.android.com/guide/topics/manifest/activity-element.html>`__.
- ``--icon``: A path to the png file to use as the application icon.
- ``-- permission``: A permission name for the app,
e.g. ``--permission VIBRATE``. For multiple permissions, add
multiple ``--permission`` arguments.
- ``--meta-data``: Custom key=value pairs to add in the application metadata.
- ``--presplash``: A path to the image file to use as a screen while
the application is loading.
- ``--presplash-color``: The presplash screen background color, of the
form ``#RRGGBB`` or a color name ``red``, ``green``, ``blue`` etc.
- ``--wakelock``: If the argument is included, the application will
prevent the device from sleeping.
- ``--window``: If the argument is included, the application will not
cover the Android status bar.
- ``--blacklist``: The path to a file containing blacklisted patterns
that will be excluded from the final APK. Defaults to ``./blacklist.txt``.
- ``--whitelist``: The path to a file containing whitelisted patterns
that will be included in the APK even if also blacklisted.
- ``--add-jar``: The path to a .jar file to include in the APK. To
include multiple jar files, pass this argument multiple times.
- ``--intent-filters``: A file path containing intent filter xml to be
included in AndroidManifest.xml.
- ``--service``: A service name and the Python script it should
run. See :ref:`arbitrary_scripts_services`.
- ``add-source``: Add a source directory to the app's Java code.
- ``--port``: The port on localhost that the WebView will
access. Defaults to 5000.
Build options
%%%%%%%%%%%%%
The sdl2 bootstrap supports the following additional command line
options (this list may not be exhaustive):
- ``--private``: The directory containing your project files.
- ``--dir``: The directory containing your project files if you want
them to be unpacked to the external storage directory rather than
the app private directory.
- ``--package``: The Java package name for your project. e.g. ``org.example.yourapp``.
- ``--name``: The app name.
- ``--version``: The version number.
- ``--orientation``: One of ``portait``, ``landscape`` or ``sensor``
to automatically rotate according to the device orientation.
- ``--icon``: A path to the png file to use as the application icon.
- ``--ignore-path``: A path to ignore when including the app
files. Pass multiple times to ignore multiple paths.
- ``-- permission``: A permission name for the app,
e.g. ``--permission VIBRATE``. For multiple permissions, add
multiple ``--permission`` arguments.
- ``--meta-data``: Custom key=value pairs to add in the application metadata.
- ``--presplash``: A path to the image file to use as a screen while
the application is loading.
- ``--wakelock``: If the argument is included, the application will
prevent the device from sleeping.
- ``--window``: If the argument is included, the application will not
cover the Android status bar.
- ``--blacklist``: The path to a file containing blacklisted patterns
that will be excluded from the final APK. Defaults to ``./blacklist.txt``.
- ``--whitelist``: The path to a file containing whitelisted patterns
that will be included in the APK even if also blacklisted.
- ``--add-jar``: The path to a .jar file to include in the APK. To
include multiple jar files, pass this argument multiple times.
- ``--intent-filters``: A file path containing intent filter xml to be
included in AndroidManifest.xml.
- ``--service``: A service name and the Python script it should
run. See :ref:`arbitrary_scripts_services`.
- ``add-source``: Add a source directory to the app's Java code.
- ``--compile-pyo``: Optimise .py files to .pyo.
- ``--resource``: A key=value pair to add in the string.xml resource file.
Requirements blacklist (APK size optimization)
----------------------------------------------
To optimize the size of the `.apk` file that p4a builds for you,
you can **blacklist** certain core components. Per default, p4a
will add python *with batteries included* as would be expected on
desktop, including openssl, sqlite3 and other components you may
not use.
To blacklist an item, specify the ``--blacklist-requirements`` option::
p4a apk ... --blacklist-requirements=sqlite3
At the moment, the following core components can be blacklisted
(if you don't want to use them) to decrease APK size:
- ``android`` disables p4a's android module (see :ref:`reference-label-for-android-module`)
- ``libffi`` disables ctypes stdlib module
- ``openssl`` disables ssl stdlib module
- ``sqlite3`` disables sqlite3 stdlib module