|
| 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 |
0 commit comments