Skip to content

Commit 9b276b5

Browse files
committed
Add docs for building APK via Docker image
1 parent 819cecd commit 9b276b5

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

doc/source/docker.rst

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
.. _docker:
2+
3+
Docker
4+
======
5+
6+
Currently we use a containerized build for testing Python for Android recipes.
7+
Docker supports three big platforms either directly with the kernel or via
8+
using headless VirtualBox and a small distro to run itself on.
9+
10+
While this is not the actively supported way to build applications, if you are
11+
willing to play with the approach, you can use the ``Dockerfile`` to build
12+
the Docker image we use in ``.travis.yml`` for CI builds and create an Android
13+
application with that in a container. This approach allows you to build Android
14+
applications on all platforms Docker engine supports. These steps assume you
15+
already have Docker preinstalled and set up.
16+
17+
.. warning::
18+
This approach is highly space unfriendly! The more layers (``commit``) or
19+
even Docker images (``build``) you create the more space it'll consume.
20+
Within the Docker image there is Android + Crystax SDK and NDK + various
21+
dependencies. Within the custom diff made by building the distribution
22+
there is another big chunk of space eaten. The very basic stuff such as
23+
a distribution with: CPython 3, setuptools, Python for Android ``android``
24+
module, SDL2 (+ deps), PyJNIus and Kivy takes almost 13 GB. Check your free
25+
space first!
26+
27+
1. Clone the repository::
28+
29+
git clone https://github.com/kivy/python-for-android
30+
31+
2. Build the image with name ``p4a``::
32+
33+
docker build --tag p4a .
34+
35+
.. note::
36+
You need to be in the ``python-for-android`` for the Docker build context
37+
and you can optionally use ``--file`` flag to specify the path to the
38+
``Dockerfile`` location.
39+
40+
3. Create a container from ``p4a`` image with copied ``testapps`` folder
41+
in the image mounted to the same one in the cloned repo on the host::
42+
43+
docker run \
44+
--interactive \
45+
--tty \
46+
--volume ".../testapps":/home/user/testapps \
47+
p4a sh -c
48+
'. venv/bin/activate \
49+
&& cd testapps \
50+
&& python setup_testapp_python3.py apk \
51+
--sdk-dir $ANDROID_SDK_HOME \
52+
--ndk-dir $ANDROID_NDK_HOME'
53+
54+
.. note::
55+
On Windows you might need to use quotes and forward-slash path for volume
56+
"/c/Users/.../python-for-android/testapps":/home/user/testapps
57+
58+
.. warning::
59+
On Windows ``gradlew`` will attempt to use 'bash\r' command which is
60+
a result of Windows line endings. For that you'll need to install
61+
``dos2unix`` package into the image.
62+
63+
4. Preserve the distribution you've already built (optional, but recommended):
64+
65+
docker commit $(docker ps --last=1 --quiet) my_p4a_dist
66+
67+
5. Find the ``.APK`` file on this location::
68+
69+
ls -lah testapps

doc/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Contents
3636
apis
3737
troubleshooting
3838
launcher
39+
docker
3940
contribute
4041
old_toolchain/index.rst
4142

0 commit comments

Comments
 (0)