|
6 | 6 | Python for Android
|
7 | 7 | ==================
|
8 | 8 |
|
9 |
| -Contents: |
10 |
| - |
11 |
| -.. toctree:: |
12 |
| - :maxdepth: 2 |
13 |
| - |
14 | 9 | Python for android is a project to create your own Python distribution
|
15 | 10 | including the modules you want, and create an apk including python, libs, and
|
16 | 11 | your application.
|
17 | 12 |
|
18 |
| -In terms of comparaison, you can check how Python for android can be useful |
19 |
| -compared to other projects. |
20 |
| - |
21 |
| -+--------------------+---------------+---------------+----------------+--------------+ |
22 |
| -| Project | Native Python | GUI libraries | APK generation | Custom build | |
23 |
| -+====================+===============+===============+================+==============+ |
24 |
| -| Python for android | Yes | Yes | Yes | Yes | |
25 |
| -+--------------------+---------------+---------------+----------------+--------------+ |
26 |
| -| PGS4A | Yes | Yes | Yes | No | |
27 |
| -+--------------------+---------------+---------------+----------------+--------------+ |
28 |
| -| Android scripting | No | No | No | No | |
29 |
| -+--------------------+---------------+---------------+----------------+--------------+ |
30 |
| -| Python on a chip | No | No | No | No | |
31 |
| -+--------------------+---------------+---------------+----------------+--------------+ |
32 |
| - |
33 |
| -.. note:: |
34 |
| - |
35 |
| - For the moment, we are shipping only one "java bootstrap" needed for |
36 |
| - decompressing all the files of your project, create an OpenGL ES 2.0 |
37 |
| - surface, handle touch input and manage an audio thread. |
38 |
| - |
39 |
| - If you want to use it without kivy module (an opengl es 2.0 ui toolkit), |
40 |
| - then you might want a lighter java bootstrap, that we don't have right now. |
41 |
| - Help is welcome :) |
42 |
| - |
43 |
| - |
44 |
| -Prerequisites |
45 |
| -------------- |
46 |
| - |
47 |
| -.. warning:: |
48 |
| - |
49 |
| - The current version is tested only on Ubuntu oneiric (11.10). If it doesn't |
50 |
| - work on another platform, send us patch, not bug report. |
51 |
| - |
52 |
| -You need the minimal environment for building python. Note that other libraries |
53 |
| -might need other tools (cython is used by some recipes, and ccache to speedup the build):: |
54 |
| - |
55 |
| - sudo apt-get install build-essential patch git-core ccache cython ant |
56 |
| - |
57 |
| -You must have android SDK and NDK. You can download them at:: |
58 |
| - |
59 |
| - http://developer.android.com/sdk/index.html |
60 |
| - http://developer.android.com/sdk/ndk/index.html |
61 |
| - |
62 |
| -If it's your very first time into android SDK, don't forget to follow |
63 |
| -documentation for recommended components at:: |
64 |
| - |
65 |
| - http://developer.android.com/sdk/installing.html#which |
66 |
| - |
67 |
| - You need to download at least one platform into your environment, so |
68 |
| - that you will be able to compile your application and set up an Android |
69 |
| - Virtual Device (AVD) to run it on (in the emulator). To start with, |
70 |
| - just download the latest version of the platform. Later, if you plan to |
71 |
| - publish your application, you will want to download other platforms as |
72 |
| - well, so that you can test your application on the full range of |
73 |
| - Android platform versions that your application supports. |
74 |
| - |
75 |
| -After installing them, export both installation path, NDK version and API to use:: |
76 |
| - |
77 |
| - export ANDROIDSDK=/path/to/android-sdk |
78 |
| - export ANDROIDNDK=/path/to/android-ndk |
79 |
| - export ANDROIDNDKVER=rX |
80 |
| - export ANDROIDAPI=X |
81 |
| - |
82 |
| - # example |
83 |
| - export ANDROIDSDK="/home/tito/code/android/android-sdk-linux_86" |
84 |
| - export ANDROIDNDK="/home/tito/code/android/android-ndk-r7" |
85 |
| - export ANDROIDNDKVER=r7 |
86 |
| - export ANDROIDAPI=14 |
87 |
| - |
88 |
| - |
89 |
| -Usage |
90 |
| ------ |
91 |
| - |
92 |
| -Step 1: compile the toolchain |
93 |
| -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
94 |
| - |
95 |
| -If you want to compile the toolchain with only kivy module:: |
96 |
| - |
97 |
| - ./distribute.sh -m "kivy" |
98 |
| - |
99 |
| -After a long time, you'll get a "dist/default" directory containing all the compiled |
100 |
| -libraries and build.py script to package your application using thoses |
101 |
| -libraries. |
102 |
| - |
103 |
| -You can include other libraries to compile using `-m`:: |
104 |
| - |
105 |
| - ./distribute.sh -m "openssl kivy" |
106 |
| - ./distribute.sh -m "pil ffmpeg kivy" |
107 |
| - |
108 |
| -Available options to `distribute.sh`:: |
109 |
| - |
110 |
| - -d directory Name of the distribution directory |
111 |
| - -h Show this help |
112 |
| - -l Show a list of available modules |
113 |
| - -m 'mod1 mod2' Modules to include |
114 |
| - -f Restart from scratch (remove the current build) |
115 |
| - |
116 |
| -Step 2: package your application |
117 |
| -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
118 |
| - |
119 |
| -Go fo your custom python distribution:: |
120 |
| - |
121 |
| - cd dist/default |
122 |
| - |
123 |
| -Use the build.py for creating the APK:: |
124 |
| - |
125 |
| - ./build.py --package org.test.touchtracer --name touchtracer \ |
126 |
| - --version 1.0 --dir ~/code/kivy/examples/demo/touchtracer debug |
127 |
| - |
128 |
| -Then, the android package (APK) will be generated at: |
129 |
| - |
130 |
| - bin/touchtracer-1.0-debug.apk |
131 |
| - |
132 |
| -Available options to `build.py`:: |
133 |
| - |
134 |
| - -h, --help show this help message and exit |
135 |
| - --package PACKAGE The name of the java package the project will be |
136 |
| - packaged under. |
137 |
| - --name NAME The human-readable name of the project. |
138 |
| - --version VERSION The version number of the project. This should consist |
139 |
| - of numbers and dots, and should have the same number |
140 |
| - of groups of numbers as previous versions. |
141 |
| - --numeric-version NUMERIC_VERSION |
142 |
| - The numeric version number of the project. If not |
143 |
| - given, this is automatically computed from the |
144 |
| - version. |
145 |
| - --dir DIR The directory containing public files for the project. |
146 |
| - --private PRIVATE The directory containing additional private files for |
147 |
| - the project. |
148 |
| - --launcher Provide this argument to build a multi-app launcher, |
149 |
| - rather than a single app. |
150 |
| - --icon-name ICON_NAME |
151 |
| - The name of the project's launcher icon. |
152 |
| - --orientation ORIENTATION |
153 |
| - The orientation that the game will display in. Usually |
154 |
| - one of "landscape" or "portrait". |
155 |
| - --permission PERMISSIONS |
156 |
| - The permissions to give this app. |
157 |
| - --ignore-path IGNORE_PATH |
158 |
| - Ignore path when building the app |
159 |
| - --icon ICON A png file to use as the icon for the application. |
160 |
| - --presplash PRESPLASH |
161 |
| - A jpeg file to use as a screen while the application |
162 |
| - is loading. |
163 |
| - --install-location INSTALL_LOCATION |
164 |
| - The default install location. Should be "auto", |
165 |
| - "preferExternal" or "internalOnly". |
166 |
| - --compile-pyo Compile all .py files to .pyo, and only distribute the |
167 |
| - compiled bytecode. |
168 |
| - --blacklist BLACKLIST |
169 |
| - Use a blacklist file to match unwanted file in the |
170 |
| - final APK |
171 |
| - |
172 |
| - |
173 |
| -How does it work ? |
174 |
| ------------------- |
175 |
| - |
176 |
| -To be able to run Python on android, you need to compile it for android. And |
177 |
| -you need to compile all the libraries you want for android too. |
178 |
| -Since Python is a language, not a toolkit, you cannot draw any user interface |
179 |
| -with it: you need to use a toolkit for it. Kivy can be one of them. |
180 |
| - |
181 |
| -So for a simple ui project, the first step is to compile Python + Kivy + all |
182 |
| -others libraries. Then you'll have what we call a "distribution". |
183 |
| -A distribution is composed of: |
184 |
| - |
185 |
| -- Python libraries |
186 |
| -- All selected libraries (kivy, pygame, pil...) |
187 |
| -- A java bootstrap |
188 |
| -- A build script |
189 |
| - |
190 |
| -You'll use the build script for create an "apk": an android package. |
191 |
| - |
192 |
| - |
193 |
| -Customize your distribution |
194 |
| ---------------------------- |
195 |
| - |
196 |
| -The basic layout of a distribution is:: |
197 |
| - |
198 |
| - AndroidManifest.xml - (*) android manifest (generated from templates) |
199 |
| - assets/ |
200 |
| - private.mp3 - (*) fake package that will contain all the python installation |
201 |
| - public.mp3 - (*) fake package that will contain your application |
202 |
| - bin/ - contain all the apk generated from build.py |
203 |
| - blacklist.txt - list of file patterns to not include in the APK |
204 |
| - buildlib/ - internals libraries for build.py |
205 |
| - build.py - build script to use for packaging your application |
206 |
| - build.xml - (*) build settings (generated from templates) |
207 |
| - default.properties - settings generated from your distribute.sh |
208 |
| - libs/ - contain all the compiled libraries |
209 |
| - local.properties - settings generated from your distribute.sh |
210 |
| - private/ - private directory containing all the python files |
211 |
| - lib/ this is where you can remove or add python libs. |
212 |
| - python2.7/ by default, some modules are already removed (tests, idlelib, ...) |
213 |
| - project.properties - settings generated from your distribute.sh |
214 |
| - python-install/ - the whole python installation, generated from distribute.sh |
215 |
| - not included in the final package. |
216 |
| - res/ - (*) android resource (generated from build.py) |
217 |
| - src/ - Java bootstrap |
218 |
| - templates/ - Templates used by build.py |
219 |
| - |
220 |
| - (*): Theses files are automatically generated from build.py, don't change them directly ! |
221 |
| - |
222 |
| - |
223 |
| -Available modules |
224 |
| ------------------ |
225 |
| - |
226 |
| -List of available modules: jpeg pil png sdl sqlite3 pygame kivy android |
227 |
| -libxml2 libxslt lxml ffmpeg openssl chipmunk |
228 |
| - |
229 |
| -The up-to-date list is available at: |
230 |
| -https://github.com/kivy/python-for-android/tree/master/recipes |
231 |
| - |
232 |
| -Only hostpython and python are 2 mandatory recipes, used for building |
233 |
| -hostpython / target python libraries. |
234 |
| - |
235 |
| - |
236 |
| -Create your own recipes |
237 |
| ------------------------ |
238 |
| - |
239 |
| -A recipe is a script that contain the "definition" of a module to compile. |
240 |
| -The directory layout of a recipe for a <modulename> is something like:: |
241 |
| - |
242 |
| - python-for-android/recipes/<modulename>/recipe.sh |
243 |
| - python-for-android/recipes/<modulename>/patches/ |
244 |
| - python-for-android/recipes/<modulename>/patches/fix-path.patch |
245 |
| - |
246 |
| -When building, all the recipe build must go to:: |
247 |
| - |
248 |
| - python-for-android/build/<modulename>/<archiveroot> |
249 |
| - |
250 |
| -For example, if you want to create a recipe for sdl, do:: |
251 |
| - |
252 |
| - cd python-for-android/recipes |
253 |
| - mkdir sdl |
254 |
| - cp recipe.sh.tmpl sdl/recipe.sh |
255 |
| - sed -i 's#XXX#sdl#' sdl/recipe.sh |
256 |
| - |
257 |
| -Then, edit the sdl/recipe.sh to adjust other information (version, url) and |
258 |
| -complete build function. |
259 |
| - |
260 |
| - |
261 |
| -Related project |
262 |
| ---------------- |
263 |
| - |
264 |
| -- PGS4A: http://pygame.renpy.org/ |
265 |
| -- Android scripting: http://code.google.com/p/android-scripting/ |
266 |
| -- Python on a chip: http://code.google.com/p/python-on-a-chip/ |
267 |
| - |
268 |
| - |
269 |
| -TODO |
270 |
| ----- |
271 |
| - |
272 |
| -- jni/Android.mk must not include ttf/image/mixer if not asked by the user |
273 |
| -- Python try always to import name.so, namemodule.so, name.py, name.pyo ? |
274 |
| -- restore libpymodules.so loading to reduce the number of dlopen. |
| 13 | +.. toctree:: |
| 14 | + :maxdepth: 2 |
| 15 | + |
| 16 | + introduction.rst |
| 17 | + prerequisites.rst |
| 18 | + usage.rst |
| 19 | + howitworks.rst |
| 20 | + customize.rst |
| 21 | + recipes.rst |
| 22 | + related.rst |
275 | 23 |
|
276 | 24 | Indices and tables
|
277 | 25 | ==================
|
|
0 commit comments