@@ -9,27 +9,37 @@ for android as p4a in this documentation.
9
9
Concepts
10
10
--------
11
11
12
- - requirements: For p4a, your applications dependencies are
13
- requirements similar to the standard `requirements.txt `, but with
14
- one difference: p4a will search for a recipe first instead of
15
- installing requirements with pip.
12
+ *Basic: *
16
13
17
- - recipe: A recipe is a file that defines how to compile a
18
- requirement. Any libraries that have a Python extension *must * have
19
- a recipe in p4a, or compilation will fail. If there is no recipe for
20
- a requirement, it will be downloaded using pip.
14
+ - **requirements: ** For p4a, all your app's dependencies must be specified
15
+ via ``--requirements `` similar to the standard `requirements.txt `.
16
+ (Unless you specify them via a `setup.py `/`install_requires `)
17
+ All dependencies will be mapped to "recipes" if any exist, so that
18
+ many common libraries will just work. See "recipe" below for details.
21
19
22
- - build: A build refers to a compiled recipe.
20
+ - **distribution: ** A distribution is the final "build" of your
21
+ compiled project + requirements, as an Android project assembled by
22
+ p4a that can be turned directly into an APK. p4a can contain multiple
23
+ distributions with different sets of requirements.
23
24
24
- - distribution: A distribution is the final "build" of all your
25
- compiled requirements, as an Android project that can be turned
26
- directly into an APK. p4a can contain multiple distributions with
27
- different sets of requirements.
25
+ - **build: ** A build refers to a compiled recipe or distribution.
28
26
29
- - bootstrap: A bootstrap is the app backend that will start your
30
- application. Your application could use SDL2 as a base,
31
- or a web backend like Flask with a WebView bootstrap. Different
32
- bootstraps can have different build options.
27
+ - **bootstrap: ** A bootstrap is the app backend that will start your
28
+ application. The default for graphical applications is SDL2.
29
+ You can also use e.g. the webview for web apps, or service_only for
30
+ background services. Different bootstraps have different additional
31
+ build options.
32
+
33
+ *Advanced: *
34
+
35
+ - **recipe: **
36
+ A recipe is a file telling p4a how to install a requirement
37
+ that isn't by default fully Android compatible.
38
+ This is often necessary for Cython or C/C++-using python extensions.
39
+ p4a has recipes for many common libraries already included, and any
40
+ dependency you specified will be automatically mapped to its recipe.
41
+ If a dependency doesn't work and has no recipe included in p4a,
42
+ then it may need one to work.
33
43
34
44
35
45
Installation
@@ -75,14 +85,20 @@ install most of these with::
75
85
On Arch Linux (64 bit) you should be able to run the following to
76
86
install most of the dependencies (note: this list may not be
77
87
complete). gcc-multilib will conflict with (and replace) gcc if not
78
- already installed. If your installation is already 32-bit, install the
79
- same packages but without ``lib32- `` or ``-multilib ``::
88
+ already installed::
80
89
81
90
sudo pacman -S jdk7-openjdk python2 python2-pip python2-kivy mesa-libgl lib32-mesa-libgl lib32-sdl2 lib32-sdl2_image lib32-sdl2_mixer sdl2_ttf unzip gcc-multilib gcc-libs-multilib
82
91
83
92
Installing Android SDK
84
93
~~~~~~~~~~~~~~~~~~~~~~
85
94
95
+ .. warning ::
96
+ python-for-android is often picky about the **SDK/NDK versions. **
97
+ Pick the recommended ones from below to avoid problems.
98
+
99
+ Basic SDK install
100
+ `````````````````
101
+
86
102
You need to download and unpack the Android SDK and NDK to a directory (let's say $HOME/Documents/):
87
103
88
104
- `Android SDK <https://developer.android.com/studio/index.html >`_
@@ -94,31 +110,22 @@ named ``tools``, and you will need to run extra commands to install
94
110
the SDK packages needed.
95
111
96
112
For Android NDK, note that modern releases will only work on a 64-bit
97
- operating system. The minimal, and recommended, NDK version to use is r17c:
113
+ operating system. ** The minimal, and recommended, NDK version to use is r17c: **
98
114
99
115
- `Go to ndk downloads page <https://developer.android.com/ndk/downloads/ >`_
100
116
- Windows users should create a virtual machine with an GNU Linux os
101
117
installed, and then you can follow the described instructions from within
102
118
your virtual machine.
103
119
104
- If you are using a 32-bit distribution (or hardware),
105
- the latest usable NDK version is r10e, which can be downloaded here:
106
120
107
- - `Legacy 32-bit Linux NDK r10e <http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86.bin >`_
121
+ Platform and build tools
122
+ ````````````````````````
108
123
109
- .. warning ::
110
- **32-bit distributions **
111
-
112
- Since the python2 recipe updated to version 2.7.15, the build system has
113
- been changed and you should use an old release of python-for-android, which
114
- contains the legacy python recipe (v2.7.2). The last python-for-android
115
- release with the legacy version of python is version
116
- `0.6.0 <https://github.com/kivy/python-for-android/archive/0.6.0.zip >`_.
117
-
118
- First, install an API platform to target. You can replace ``27 `` with
119
- a different platform number, but keep in mind **other API versions
120
- are less well-tested **, and older devices are still supported
121
- (down to the specified *minimum * API/NDK API level):
124
+ First, install an API platform to target. **The recommended *target* API
125
+ level is 27 **, you can replace it with a different number but
126
+ keep in mind other API versions are less well-tested and older devices
127
+ are still supported down to the **recommended specified *minimum*
128
+ API/NDK API level 21 **:
122
129
123
130
$SDK_DIR/tools/bin/sdkmanager "platforms;android-27"
124
131
@@ -128,13 +135,17 @@ possibilities, but 26.0.2 is the latest version at the time of writing::
128
135
129
136
$SDK_DIR/tools/bin/sdkmanager "build-tools;26.0.2"
130
137
131
- Then, you can edit your ``~/.bashrc `` or other favorite shell to include new environment variables necessary for building on android::
138
+ Configure p4a to use your SDK/NDK
139
+ `````````````````````````````````
140
+
141
+ Then, you can edit your ``~/.bashrc `` or other favorite shell to include new environment
142
+ variables necessary for building on android::
132
143
133
144
# Adjust the paths!
134
145
export ANDROIDSDK="$HOME/Documents/android-sdk-27"
135
146
export ANDROIDNDK="$HOME/Documents/android-ndk-r17c"
136
- export ANDROIDAPI="26 " # Target API version of your application
137
- export NDKAPI="19 " # Minimum supported API version of your application
147
+ export ANDROIDAPI="27 " # Target API version of your application
148
+ export NDKAPI="21 " # Minimum supported API version of your application
138
149
export ANDROIDNDKVER="r10e" # Version of the NDK you installed
139
150
140
151
You have the possibility to configure on any command the PATH to the SDK, NDK and Android API using:
@@ -158,9 +169,9 @@ and the requirements::
158
169
159
170
p4a apk --private $HOME/code/myapp --package=org.example.myapp --name "My application" --version 0.1 --bootstrap=sdl2 --requirements=python3,kivy
160
171
161
- **Note on ` --requirements`: you must add all
172
+ **Note on ** `` --requirements ``: ** you must add all
162
173
libraries/dependencies your app needs to run. **
163
- Example: `--requirements=python3,kivy,vispy `. For an SDL2 app,
174
+ Example: `` --requirements=python3,kivy,vispy ` `. For an SDL2 app,
164
175
`kivy ` is not needed, but you need to add any wrappers you might
165
176
use (e.g. `pysdl2 `).
166
177
@@ -175,8 +186,6 @@ an `.apk` file.
175
186
it will possibly no longer receive patches by the python creators
176
187
themselves in 2020. Migration to Python 3 is recommended!
177
188
178
- - You can also use ``--bootstrap=pygame ``, but this bootstrap
179
- is deprecated and not well-tested.
180
189
181
190
Build a WebView application
182
191
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -188,7 +197,7 @@ well as the requirements::
188
197
p4a apk --private $HOME/code/myapp --package=org.example.myapp --name "My WebView Application" --version 0.1 --bootstrap=webview --requirements=flask --port=5000
189
198
190
199
**Please note as with kivy/SDL2, you need to specify all your
191
- additional requirements/depenencies . **
200
+ additional requirements/dependencies . **
192
201
193
202
You can also replace flask with another web framework.
194
203
0 commit comments