Skip to content

Commit 53c485b

Browse files
author
Pol Canelles
committed
Merge branch 'master' of https://github.com/kivy/python-for-android into fix-env-py2
# Solved Conflicts: pythonforandroid/recipes/m2crypto/__init__.py
2 parents 013a23e + 149d9ea commit 53c485b

File tree

107 files changed

+5291
-721
lines changed

Some content is hidden

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

107 files changed

+5291
-721
lines changed

README.md

Lines changed: 35 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,45 @@
1-
# Python for Android
1+
# python-for-android
22

3-
Python for Android is a project to create your own Python distribution
4-
including the modules you want, and create an apk including python,
5-
libs, and your application.
3+
python-for-android is a packager for Python apps on Android. You can
4+
create your own Python distribution including the modules and
5+
dependencies you want, and bundle it in an APK along with your own
6+
code.
67

7-
These tools were recently rewritten to provide a new, easier to use
8-
and extend interface. If you are looking for the old toolchain with
9-
distribute.sh and build.py, it is still available at
10-
https://github.com/kivy/python-for-android/tree/old_toolchain, and
11-
issues and PRs relating to this branch are still accepted. However,
12-
the new toolchain contains all the same functionality via the built in
13-
pygame bootstrap.
8+
Features include:
9+
10+
- Support for building with both Python 2 and Python 3.
11+
- Different app backends including Kivy, PySDL2, and a WebView with
12+
Python webserver.
13+
- Automatic support for most pure Python modules, and built in support
14+
for many others, including popular dependencies such as numpy and
15+
sqlalchemy.
16+
- Multiple architecture targets, for APKs optimised on any given device.
1417

1518
For documentation and support, see:
1619

17-
- Website: http://python-for-android.rtfd.org/
20+
- Website: http://python-for-android.readthedocs.io
1821
- Mailing list: https://groups.google.com/forum/#!forum/kivy-users or
1922
https://groups.google.com/forum/#!forum/python-android.
2023

21-
Broad goals of the revamp project include:
22-
23-
- ✓ Replace the old toolchain with a more extensible pythonic one
24-
- ✓ Support SDL2
25-
- ✓ Support multiple bootstraps (user-chosen java + NDK code, e.g. for
26-
multiple graphics backends or non-Kivy projects)
27-
- ✓ Support python3 (it finally works!)
28-
- (WIP) Support some kind of binary distribution, including on windows (semi-implemented, just needs finishing)
29-
- ✓ Be a standalone Pypi module (not on pypi yet but setup.py works)
30-
- ✓ Support multiple architectures (full multiarch builds not complete, but arm and x86 with different config both work now)
31-
32-
We are currently working to stabilise all parts of the toolchain and
33-
add more features. Support for pygame-based APKs is almost feature
34-
complete with the old toolchain. Testing and contributions are
35-
welcome.
36-
37-
The recent replacement of the master branch with the revamp will have
38-
rendered most/all PRs invalid. Please retarget revamp PRs on the
39-
master branch, or PRs for the old toolchain on the old_toolchain
40-
branch.
24+
In 2015 these tools were rewritten to provide a new, easier to use and
25+
extend interface. If you are looking for the old toolchain with
26+
distribute.sh and build.py, it is still available at
27+
https://github.com/kivy/python-for-android/tree/old_toolchain, and
28+
issues and PRs relating to this branch are still accepted. However,
29+
the new toolchain contains all the same functionality via the built in
30+
pygame bootstrap.
4131

4232
# Documentation
4333

4434
Follow the
4535
[quickstart instructions](https://python-for-android.readthedocs.org/en/latest/quickstart/)
46-
to install and begin creating APK.
36+
to install and begin creating APKs.
37+
38+
Quick instructions to start would be::
4739

48-
Quick instructions to start would be:
40+
pip install python-for-android
41+
42+
or to test the master branch::
4943

5044
pip install git+https://github.com/kivy/python-for-android.git
5145

@@ -63,39 +57,9 @@ If you did this, to build an APK with SDL2 you can try e.g.
6357

6458
p4a apk --requirements=kivy --private /home/asandy/devel/planewave_frozen/ --package=net.inclem.planewavessdl2 --name="planewavessdl2" --version=0.5 --bootstrap=sdl2
6559

66-
For full instructions and parameter options, see the documentation
67-
linked above.
68-
69-
# Known missing stuff from P4A
70-
71-
Relating to all bootstraps:
72-
- Some recipes/components aren't stripped properly of doc etc.
73-
- Downloaded file md5 and headers aren't checked
74-
75-
Relating to SDL2 only:
76-
- Public dir installation
77-
- Keyboard height getter
78-
- Billing support
79-
- Kivy Launcher build (can now be implemented as a bootstrap...maybe?)
80-
- Probably some other stuff
81-
82-
Here are some specific things relating to changes in p4a itself since
83-
the reference commit that the revamp is based on:
84-
85-
# Current status
86-
87-
python-for-android is fully ready for use. We are working towards a versioned release.
88-
89-
# Development notes
90-
91-
Original reference commit of p4a master was
92-
7c8d4ce9db384528f7ea83e0841fe2464a558db8 - possibly some things after
93-
this need adding to the new toolchain. Some of the major later
94-
additons, including ctypes in the python build, have already been
95-
merged here.
60+
For full instructions and parameter options, see the documentation.
9661

97-
Support
98-
-------
62+
# Support
9963

10064
If you need assistance, you can ask for help on our mailing list:
10165

@@ -108,12 +72,11 @@ We also have an IRC channel:
10872
* Port: 6667, 6697 (SSL only)
10973
* Channel: #kivy
11074

111-
Contributing
112-
------------
75+
# Contributing
11376

11477
We love pull requests and discussing novel ideas. Check out our
11578
[contribution guide](http://kivy.org/docs/contribute.html) and
116-
feel free to improve Python for Android.
79+
feel free to improve python-for-android.
11780

11881
The following mailing list and IRC channel are used exclusively for
11982
discussions about developing the Kivy framework and its sister projects:
@@ -125,10 +88,9 @@ IRC channel:
12588

12689
* Server: irc.freenode.net
12790
* Port: 6667, 6697 (SSL only)
128-
* Channel: #kivy-dev
91+
* Channel: #kivy or #kivy-dev
12992

130-
License
131-
-------
93+
# License
13294

133-
Python for Android is released under the terms of the MIT License. Please refer to the
95+
python-for-android is released under the terms of the MIT License. Please refer to the
13496
LICENSE file.

doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# You can set these variables from the command line.
55
SPHINXOPTS =
6-
SPHINXBUILD = sphinx-build2
6+
SPHINXBUILD = sphinx-build
77
PAPER =
88
BUILDDIR = build
99

doc/source/_static/.empty

Whitespace-only changes.

doc/source/apis.rst

Lines changed: 79 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,40 @@ Accessing Android APIs
33
======================
44

55
When writing an Android application you may want to access the normal
6-
Android APIs, which are available in Java. It is by calling these that
7-
you would normally accomplish everything from vibration, to opening
8-
other applications, to accessing sensor data, to controlling settings
9-
like screen orientation and wakelocks.
10-
11-
These APIs can be accessed from Python to perform all of these tasks
12-
and many more. This is made possible by the `Pyjnius
13-
<http://pyjnius.readthedocs.org/en/latest/>`_ module, a Python
14-
library for automatically wrapping Java and making it callable from
15-
Python code. This is fairly simple to use, though not very Pythonic
16-
and inherits Java's verbosity. For this reason the Kivy organisation
17-
also created `Plyer <https://plyer.readthedocs.org/en/latest/>`_,
18-
which further wraps specific APIs in a Pythonic and cross-platform
19-
way - so in fact you can call the same code in Python but have it do
20-
the right thing also on platforms other than Android.
21-
22-
These are both independent projects whose documentation is linked
23-
above, and you can check this to learn about all the things they can
24-
do. The following sections give some simple introductory examples,
25-
along with explanation of how to include these modules in your APKs.
6+
Android Java APIs, in order to control your application's appearance
7+
(fullscreen, orientation etc.), interact with other apps or use
8+
hardware like vibration and sensors.
9+
10+
You can access these with `Pyjnius
11+
<http://pyjnius.readthedocs.org/en/latest/>`_, a Python library for
12+
automatically wrapping Java and making it callable from Python
13+
code. Pyjnius is fairly simple to use, but not very Pythonic and it
14+
inherits Java's verbosity. For this reason the Kivy organisation also
15+
created `Plyer <https://plyer.readthedocs.org/en/latest/>`_, which
16+
further wraps specific APIs in a Pythonic and cross-platform way; you
17+
can call the same code in Python but have it do the right thing also
18+
on platforms other than Android.
19+
20+
Pyjnius and Plyer are independent projects whose documentation is
21+
linked above. See below for some simple introductory examples, and
22+
explanation of how to include these modules in your APKs.
23+
24+
This page also documents the ``android`` module which you can include
25+
with p4a, but this is mostly replaced by Pyjnius and is not
26+
recommended for use in new applications.
2627

2728

2829
Using Pyjnius
2930
-------------
3031

31-
Pyjnius lets you call the Android API directly from Python; this let's
32-
you do almost everything you can (and probably would) do in a Java
33-
app. Pyjnius is works by dynamically wrapping Java classes, so you
34-
don't have to wait for any particular feature to be pre-supported.
32+
Pyjnius lets you call the Android API directly from Python Pyjnius is
33+
works by dynamically wrapping Java classes, so you don't have to wait
34+
for any particular feature to be pre-supported.
3535

36-
You can include Pyjnius in your APKs by adding the `pyjnius` or
37-
`pyjniussdl2` recipes to your build requirements (the former works
38-
with Pygame/SDL1, the latter with SDL2, the need to make this choice
39-
will be removed later when pyjnius internally supports multiple
40-
Android backends). It is automatically included in any APK containing
41-
Kivy, in which case you don't need to specify it manually.
36+
You can include Pyjnius in your APKs by adding `pyjnius` to your build
37+
requirements, e.g. :code:`--requirements=flask,pyjnius`. It is
38+
automatically included in any APK containing Kivy, in which case you
39+
don't need to specify it manually.
4240

4341
The basic mechanism of Pyjnius is the `autoclass` command, which wraps
4442
a Java class. For instance, here is the code to vibrate your device::
@@ -87,17 +85,16 @@ You can check the `Pyjnius documentation <Pyjnius_>`_ for further details.
8785
Using Plyer
8886
-----------
8987

90-
Plyer aims to provide a much less verbose, Pythonic wrapper to
91-
platform-specific APIs. Android is a supported platform, but it also
92-
supports iOS and desktop operating systems, with the idea that the
93-
same Plyer code would do the right thing on any of them, though Plyer
94-
is a work in progress and not all platforms support all Plyer calls
95-
yet. This is the disadvantage of Plyer, it does not support all APIs
96-
yet, but you can always Pyjnius to call anything that is currently
97-
missing.
88+
Plyer provides a much less verbose, Pythonic wrapper to
89+
platform-specific APIs. It supports Android as well as iOS and desktop
90+
operating systems, though plyer is a work in progress and not all
91+
platforms support all Plyer calls yet.
92+
93+
Plyer does not support all APIs yet, but you can always Pyjnius to
94+
call anything that is currently missing.
9895

9996
You can include Plyer in your APKs by adding the `Plyer` recipe to
100-
your build requirements. It is not included automatically.
97+
your build requirements, e.g. :code:`--requirements=plyer`.
10198

10299
You should check the `Plyer documentation <Plyer_>`_ for details of all supported
103100
facades (platform APIs), but as an example the following is how you
@@ -106,8 +103,47 @@ would achieve vibration as described in the Pyjnius section above::
106103
from plyer.vibrator import vibrate
107104
vibrate(10) # in Plyer, the argument is in seconds
108105

109-
This is obviously *much* less verbose!
106+
This is obviously *much* less verbose than with Pyjnius!
107+
108+
109+
Using ``android``
110+
-----------------
111+
112+
This Cython module was used for Android API interaction with Kivy's old
113+
interface, but is now mostly replaced by Pyjnius.
114+
115+
The ``android`` Python module can be included by adding it to your
116+
requirements, e.g. :code:`--requirements=kivy,android`. It is not
117+
automatically included by Kivy unless you use the old (Pygame)
118+
bootstrap.
119+
120+
This module is not separately documented. You can read the source `on
121+
Github
122+
<https://github.com/kivy/python-for-android/tree/master/pythonforandroid/recipes/android/src/android>`__.
123+
124+
One useful facility of this module is to make
125+
:code:`webbrowser.open()` work on Android. You can replicate this
126+
effect without using the android module via the following
127+
code::
128+
129+
from jnius import autoclass
130+
131+
def open_url(url):
132+
Intent = autoclass('android.content.Intent')
133+
Uri = autoclass('android.net.Uri')
134+
browserIntent = Intent()
135+
browserIntent.setAction(Intent.ACTION_VIEW)
136+
browserIntent.setData(Uri.parse(url))
137+
currentActivity = cast('android.app.Activity', mActivity)
138+
currentActivity.startActivity(browserIntent)
139+
140+
class AndroidBrowser(object):
141+
def open(self, url, new=0, autoraise=True):
142+
open_url(url)
143+
def open_new(self, url):
144+
open_url(url)
145+
def open_new_tab(self, url):
146+
open_url(url)
110147

111-
.. warning:: At the time of writing, the Plyer recipe is not yet
112-
ported, and Plyer doesn't support SDL2. These issues will
113-
be fixed soon.
148+
import webbrowser
149+
webbrowser.register('android', AndroidBrowser, None, -1)

doc/source/bootstraps.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22
Bootstraps
33
==========
44

5+
This page is about creating new bootstrap backends. For build options
6+
of existing bootstraps (i.e. with SDL2, Pygame, Webview etc.), see
7+
:ref:`build options <bootstrap_build_options>`.
8+
59
python-for-android (p4a) supports multiple *bootstraps*. These fulfill a
610
similar role to recipes, but instead of describing how to compile a
711
specific module they describe how a full Android project may be put
812
together from a combination of individual recipes and other
913
components such as Android source code and various build files.
1014

11-
If you do not want to modify p4a, you don't need to worry about
12-
bootstraps, just make sure you specify what modules you want to use
13-
(or specify an existing bootstrap manually), and p4a will
14-
automatically build everything appropriately. The existing choices are
15-
explained on the :ref:`build options <bootstrap_build_options>` page.
16-
1715
This page describes the basics of how bootstraps work so that you can
1816
create and use your own if you like, making it easy to build new kinds
1917
of Python project for Android.

doc/source/commands.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ supply those that you need.
7575
targeted at a time, and a given distribution can only include one architecture.
7676

7777
``--bootstrap BOOTSTRAP``
78-
7978
The Java bootstrap to use for your application. You mostly don't
8079
need to worry about this or set it manually, as an appropriate
8180
bootstrap will be chosen from your ``--requirements``. Current

doc/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282

8383
# List of patterns, relative to source directory, that match files and
8484
# directories to ignore when looking for source files.
85-
exclude_patterns = []
85+
exclude_patterns = ['ext/*', ]
8686

8787
# The reST default role (used for this markup: `text`) to use for all
8888
# documents.

0 commit comments

Comments
 (0)