Skip to content

Commit d3498dd

Browse files
committed
Merge branch 'master' into ffpyplayer_new_toolchain
# Conflicts: # doc/source/quickstart.rst
2 parents 52d3526 + 06f981f commit d3498dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1224
-694
lines changed

doc/source/buildoptions.rst

Lines changed: 133 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22
Build options
33
=============
44

5-
This page contains instructions for using some of the specific python-for-android build options.
5+
This page contains instructions for using different build options.
66

77

8-
Python version
9-
--------------
10-
11-
python-for-android now supports building APKs with either python2 or
12-
python3, but these have extra requirements or potential disadvantages
13-
as below.
14-
8+
Python versions
9+
---------------
1510

1611
python2
1712
~~~~~~~
@@ -47,30 +42,24 @@ Google's official NDK which includes many improvements. You
4742
python3. You can get it `here
4843
<https://www.crystax.net/en/download>`__.
4944

50-
The python3crystax build is is handled quite differently to python2 so
45+
The python3crystax build is handled quite differently to python2 so
5146
there may be bugs or surprising behaviours. If you come across any,
5247
feel free to `open an issue
5348
<https://github.com/kivy/python-for-android>`__.
5449

55-
As this build is experimental, some features are missing and
56-
the build is not fully optimised so APKs are probably a little larger
57-
and slower than they need to be. This is currently being addressed,
58-
though it's not clear how the final result will compare to python2.
59-
6050
.. _bootstrap_build_options:
6151

62-
Bootstrap
63-
---------
52+
Bootstrap options
53+
-----------------
6454

65-
python-for-android supports multiple bootstraps, which contain the app
66-
backend that starts the app and the python interpreter, then
67-
handles interactions with the Android OS.
55+
python-for-android supports multiple app backends with different types
56+
of interface. These are called *bootstraps*.
6857

6958
Currently the following bootstraps are supported, but we hope that it
70-
it should be easy to add others if your project has different
59+
should be easy to add others if your project has different
7160
requirements. `Let us know
72-
<https://groups.google.com/forum/#!forum/python-android>`__ if there
73-
are any improvements that would help here.
61+
<https://groups.google.com/forum/#!forum/python-android>`__ if you'd
62+
like help adding a new one.
7463

7564
sdl2
7665
~~~~
@@ -89,6 +78,49 @@ and have them work with this bootstrap. It should also be possible to
8978
use e.g. pygame_sdl2, but this would need a build recipe and doesn't
9079
yet have one.
9180

81+
Build options
82+
%%%%%%%%%%%%%
83+
84+
The sdl2 bootstrap supports the following additional command line
85+
options (this list may not be exhaustive):
86+
87+
- ``--private``: The directory containing your project files.
88+
- ``--package``: The Java package name for your project. Choose e.g. ``org.example.yourapp``.
89+
- ``--name``: The app name.
90+
- ``--version``: The version number.
91+
- ``--orientation``: Usually one of ``portait``, ``landscape``,
92+
``sensor`` to automatically rotate according to the device
93+
orientation, or ``user`` to do the same but obeying the user's
94+
settings. The full list of valid options is given under
95+
``android:screenOrientation`` in the `Android documentation
96+
<https://developer.android.com/guide/topics/manifest/activity-element.html>`__.
97+
- ``--icon``: A path to the png file to use as the application icon.
98+
- ``-- permission``: A permission name for the app,
99+
e.g. ``--permission VIBRATE``. For multiple permissions, add
100+
multiple ``--permission`` arguments.
101+
- ``--meta-data``: Custom key=value pairs to add in the application metadata.
102+
- ``--presplash``: A path to the image file to use as a screen while
103+
the application is loading.
104+
- ``--presplash-color``: The presplash screen background color, of the
105+
form ``#RRGGBB`` or a color name ``red``, ``green``, ``blue`` etc.
106+
- ``--wakelock``: If the argument is included, the application will
107+
prevent the device from sleeping.
108+
- ``--window``: If the argument is included, the application will not
109+
cover the Android status bar.
110+
- ``--blacklist``: The path to a file containing blacklisted patterns
111+
that will be excluded from the final APK. Defaults to ``./blacklist.txt``.
112+
- ``--whitelist``: The path to a file containing whitelisted patterns
113+
that will be included in the APK even if also blacklisted.
114+
- ``--add-jar``: The path to a .jar file to include in the APK. To
115+
include multiple jar files, pass this argument multiple times.
116+
- ``--intent-filters``: A file path containing intent filter xml to be
117+
included in AndroidManifest.xml.
118+
- ``--service``: A service name and the Python script it should
119+
run. See :ref:`arbitrary_scripts_services`.
120+
- ``--add-source``: Add a source directory to the app's Java code.
121+
- ``--no-compile-pyo``: Do not optimise .py files to .pyo.
122+
123+
92124
webview
93125
~~~~~~~
94126

@@ -112,6 +144,43 @@ present (e.g. during the short Python loading time when first
112144
started), it will instead display a loading screen until the server is
113145
ready.
114146

147+
- ``--private``: The directory containing your project files.
148+
- ``--package``: The Java package name for your project. Choose e.g. ``org.example.yourapp``.
149+
- ``--name``: The app name.
150+
- ``--version``: The version number.
151+
- ``--orientation``: Usually one of ``portait``, ``landscape``,
152+
``sensor`` to automatically rotate according to the device
153+
orientation, or ``user`` to do the same but obeying the user's
154+
settings. The full list of valid options is given under
155+
``android:screenOrientation`` in the `Android documentation
156+
<https://developer.android.com/guide/topics/manifest/activity-element.html>`__.
157+
- ``--icon``: A path to the png file to use as the application icon.
158+
- ``-- permission``: A permission name for the app,
159+
e.g. ``--permission VIBRATE``. For multiple permissions, add
160+
multiple ``--permission`` arguments.
161+
- ``--meta-data``: Custom key=value pairs to add in the application metadata.
162+
- ``--presplash``: A path to the image file to use as a screen while
163+
the application is loading.
164+
- ``--presplash-color``: The presplash screen background color, of the
165+
form ``#RRGGBB`` or a color name ``red``, ``green``, ``blue`` etc.
166+
- ``--wakelock``: If the argument is included, the application will
167+
prevent the device from sleeping.
168+
- ``--window``: If the argument is included, the application will not
169+
cover the Android status bar.
170+
- ``--blacklist``: The path to a file containing blacklisted patterns
171+
that will be excluded from the final APK. Defaults to ``./blacklist.txt``.
172+
- ``--whitelist``: The path to a file containing whitelisted patterns
173+
that will be included in the APK even if also blacklisted.
174+
- ``--add-jar``: The path to a .jar file to include in the APK. To
175+
include multiple jar files, pass this argument multiple times.
176+
- ``--intent-filters``: A file path containing intent filter xml to be
177+
included in AndroidManifest.xml.
178+
- ``--service``: A service name and the Python script it should
179+
run. See :ref:`arbitrary_scripts_services`.
180+
- ``add-source``: Add a source directory to the app's Java code.
181+
- ``--port``: The port on localhost that the WebView will
182+
access. Defaults to 5000.
183+
115184

116185
pygame
117186
~~~~~~
@@ -126,3 +195,45 @@ apps, but hasn't been developed with this in mind.
126195
This bootstrap will eventually be deprecated in favour of sdl2, but
127196
not before the sdl2 bootstrap includes all the features that would be
128197
lost.
198+
199+
Build options
200+
%%%%%%%%%%%%%
201+
202+
The pygame bootstrap supports the following additional command line
203+
options (this list may not be exhaustive):
204+
205+
- ``--private``: The directory containing your project files.
206+
- ``--dir``: The directory containing your project files if you want
207+
them to be unpacked to the external storage directory rather than
208+
the app private directory.
209+
- ``--package``: The Java package name for your project. Choose e.g. ``org.example.yourapp``.
210+
- ``--name``: The app name.
211+
- ``--version``: The version number.
212+
- ``--orientation``: One of ``portait``, ``landscape`` or ``sensor``
213+
to automatically rotate according to the device orientation.
214+
- ``--icon``: A path to the png file to use as the application icon.
215+
- ``--ignore-path``: A path to ignore when including the app
216+
files. Pass multiple times to ignore multiple paths.
217+
- ``-- permission``: A permission name for the app,
218+
e.g. ``--permission VIBRATE``. For multiple permissions, add
219+
multiple ``--permission`` arguments.
220+
- ``--meta-data``: Custom key=value pairs to add in the application metadata.
221+
- ``--presplash``: A path to the image file to use as a screen while
222+
the application is loading.
223+
- ``--wakelock``: If the argument is included, the application will
224+
prevent the device from sleeping.
225+
- ``--window``: If the argument is included, the application will not
226+
cover the Android status bar.
227+
- ``--blacklist``: The path to a file containing blacklisted patterns
228+
that will be excluded from the final APK. Defaults to ``./blacklist.txt``.
229+
- ``--whitelist``: The path to a file containing whitelisted patterns
230+
that will be included in the APK even if also blacklisted.
231+
- ``--add-jar``: The path to a .jar file to include in the APK. To
232+
include multiple jar files, pass this argument multiple times.
233+
- ``--intent-filters``: A file path containing intent filter xml to be
234+
included in AndroidManifest.xml.
235+
- ``--service``: A service name and the Python script it should
236+
run. See :ref:`arbitrary_scripts_services`.
237+
- ``add-source``: Add a source directory to the app's Java code.
238+
- ``--compile-pyo``: Optimise .py files to .pyo.
239+
- ``--resource``: A key=value pair to add in the string.xml resource file.

doc/source/launcher.rst

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,23 @@ python-for-android.
2020
Building
2121
--------
2222

23-
The Kivy Launcher is built using python-for-android, and is currently
24-
only supported by the pygame bootstrap (there is no SDL2 launcher
25-
yet). To get the most recent versions of packages you need to clean
26-
them first, so that the packager won't grab an old package instead of
27-
fresh one.
23+
The Kivy Launcher is built using python-for-android. To get the most recent
24+
versions of packages you need to clean them first, so that the packager won't
25+
grab an old (cached) package instead of fresh one.
2826

2927
.. highlight:: none
3028

3129
::
3230

33-
p4a clean_dists
34-
p4a clean_builds
31+
p4a clean_download_cache requirements
32+
p4a clean_dists && p4a clean_builds
3533
p4a apk --requirements=requirements \
3634
--permission PERMISSION \
3735
--package=the.package.name \
3836
--name="App name" \
3937
--version=x.y.z \
4038
--android_api XY \
41-
--bootstrap=pygame \
39+
--bootstrap=pygame or sdl2 \
4240
--launcher \
4341
--minsdk 13
4442

@@ -80,6 +78,9 @@ to change other settings.
8078
After you set your `android.txt` file, you can now run the launcher
8179
and start any available app from the list.
8280

81+
To differentiate between apps in ``/sdcard/kivy`` you can include an icon
82+
named ``icon.png`` to the folder. The icon should be a square.
83+
8384
Release on the market
8485
---------------------
8586

@@ -91,10 +92,14 @@ Source code
9192
-----------
9293

9394
.. |renpy| replace:: pygame org.renpy.android
95+
.. |kivy| replace:: sdl2 org.kivy.android
9496

9597
.. _renpy:
9698
https://github.com/kivy/python-for-android/tree/master/\
9799
pythonforandroid/bootstraps/pygame/build/src/org/renpy/android
100+
.. _sdl2:
101+
https://github.com/kivy/python-for-android/tree/master/\
102+
pythonforandroid/bootstraps/sdl2/build/src/org/kivy/android
98103

99104
If you feel confident, feel free to improve the launcher. You can find the
100-
source code at |renpy|_.
105+
source code at |renpy|_ or at |kivy|_.

doc/source/recipes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ this using the ``sh`` module as follows::
181181
def build_arch(self, arch):
182182
super(YourRecipe, self).build_arch(arch)
183183
env = self.get_recipe_env(arch)
184-
sh.echo('$PATH', _env=env) # Will print the PATH entry fron the
184+
sh.echo('$PATH', _env=env) # Will print the PATH entry from the
185185
# env dict
186186

187187
You can also use the ``shprint`` helper function from the p4a

doc/source/services.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ you wish to use this method)::
3939
description='service description',
4040
arg='argument to service')
4141

42-
Arbitrary scripts
43-
~~~~~~~~~~~~~~~~~
42+
.. _arbitrary_scripts_services:
43+
44+
Arbitrary service scripts
45+
~~~~~~~~~~~~~~~~~~~~~~~~~
4446

4547
.. note:: This service method is *not supported* by the Pygame bootstrap.
4648

@@ -77,3 +79,9 @@ do pass it, the service can make use of this argument.
7779
Services support a range of options and interactions not yet
7880
documented here but all accessible via calling other methods of the
7981
``service`` reference.
82+
83+
.. note:: The app root directory for Python imports will be in the app
84+
root folder even if the service file is in a subfolder. To import from
85+
your service folder you must use e.g. ``import service.module``
86+
instead of ``import module``, if the service file is in the
87+
``service/`` folder.

doc/source/troubleshooting.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,11 @@ Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/d
152152

153153
This occurs due to a java version mismatch, it should be fixed by
154154
installing Java 8 (e.g. the openjdk-8-jdk package on Ubuntu).
155+
156+
JNI DETECTED ERROR IN APPLICATION: static jfieldID 0x0000000 not valid for class java.lang.Class<org.renpy.android.PythonActivity>
157+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
158+
159+
This error appears in the logcat log if you try to access
160+
``org.renpy.android.PythonActivity`` from within the new toolchain. To
161+
fix it, change your code to reference
162+
``org.kivy.android.PythonActivity`` instead.

pythonforandroid/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
__version__ = '0.4'
2+
__version__ = '0.5'

pythonforandroid/archs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ def get_env(self, with_flags_in_cc=True):
5757

5858
ccache = ''
5959
if self.ctx.ccache and bool(int(environ.get('USE_CCACHE', '1'))):
60-
print('ccache found, will optimize builds')
60+
# print('ccache found, will optimize builds')
6161
ccache = self.ctx.ccache + ' '
6262
env['USE_CCACHE'] = '1'
6363
env['NDK_CCACHE'] = self.ctx.ccache
6464
env.update({k: v for k, v in environ.items() if k.startswith('CCACHE_')})
6565

66-
print('path is', environ['PATH'])
6766
cc = find_executable('{command_prefix}-gcc'.format(
6867
command_prefix=command_prefix), path=environ['PATH'])
6968
if cc is None:
69+
print('Searching path are: {!r}'.format(environ['PATH']))
7070
warning('Couldn\'t find executable for CC. This indicates a '
7171
'problem locating the {} executable in the Android '
7272
'NDK, not that you don\'t have a normal compiler '
@@ -180,4 +180,3 @@ def get_env(self, with_flags_in_cc=True):
180180
env['CC'] += incpath
181181
env['CXX'] += incpath
182182
return env
183-

pythonforandroid/bootstraps/pygame/build/blacklist.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ lib-dynload/*audioop.so
8181
lib-dynload/mmap.so
8282
lib-dynload/_hotshot.so
8383
lib-dynload/_csv.so
84-
lib-dynload/future_builtins.so
8584
lib-dynload/_heapq.so
86-
lib-dynload/_json.so
8785
lib-dynload/grp.so
8886
lib-dynload/resource.so
8987
lib-dynload/pyexpat.so

pythonforandroid/bootstraps/pygame/build/build.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def parse_args(args=None):
415415
'Usually one of "landscape", "portrait" or '
416416
'"sensor"'))
417417
ap.add_argument('--permission', dest='permissions', action='append',
418-
help='The permissions to give this app.')
418+
help='The permissions to give this app.', nargs='+')
419419
ap.add_argument('--ignore-path', dest='ignore_path', action='append',
420420
help='Ignore path when building the app')
421421
ap.add_argument('--icon', dest='icon',
@@ -488,6 +488,9 @@ def parse_args(args=None):
488488

489489
if args.permissions is None:
490490
args.permissions = []
491+
elif args.permissions:
492+
if isinstance(args.permissions[0], list):
493+
args.permissions = [p for perm in args.permissions for p in perm]
491494

492495
if args.ignore_path is None:
493496
args.ignore_path = []

pythonforandroid/bootstraps/sdl2/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ def run_distribute(self):
111111
shprint(sh.mv, filen, filen.split('.')[0] + '.so')
112112
site_packages_dir = join(abspath(curdir),
113113
site_packages_dir)
114+
if 'sqlite3' not in self.ctx.recipe_build_order:
115+
with open('blacklist.txt', 'a') as fileh:
116+
fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')
114117

115118

116119
self.strip_libraries(arch)

pythonforandroid/bootstraps/sdl2/build/blacklist.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,3 @@ lib-dynload/_testcapi.so
8181

8282
# odd files
8383
plat-linux3/regen
84-
85-
#>sqlite3
86-
# conditionnal include depending if some recipes are included or not.
87-
sqlite3/*
88-
lib-dynload/_sqlite3.so
89-
#<sqlite3
90-

0 commit comments

Comments
 (0)