Skip to content

Add instructions for using Docker image for building APKs #1467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions doc/source/docker.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
.. _docker:

Docker
======

Currently we use a containerized build for testing Python for Android recipes.
Docker supports three big platforms either directly with the kernel or via
using headless VirtualBox and a small distro to run itself on.

While this is not the actively supported way to build applications, if you are
willing to play with the approach, you can use the ``Dockerfile`` to build
the Docker image we use in ``.travis.yml`` for CI builds and create an Android
application with that in a container. This approach allows you to build Android
applications on all platforms Docker engine supports. These steps assume you
already have Docker preinstalled and set up.

.. warning::
This approach is highly space unfriendly! The more layers (``commit``) or
even Docker images (``build``) you create the more space it'll consume.
Within the Docker image there is Android + Crystax SDK and NDK + various
dependencies. Within the custom diff made by building the distribution
there is another big chunk of space eaten. The very basic stuff such as
a distribution with: CPython 3, setuptools, Python for Android ``android``
module, SDL2 (+ deps), PyJNIus and Kivy takes almost 13 GB. Check your free
space first!

1. Clone the repository::

git clone https://github.com/kivy/python-for-android

2. Build the image with name ``p4a``::

docker build --tag p4a .

.. note::
You need to be in the ``python-for-android`` for the Docker build context
and you can optionally use ``--file`` flag to specify the path to the
``Dockerfile`` location.

3. Create a container from ``p4a`` image with copied ``testapps`` folder
in the image mounted to the same one in the cloned repo on the host::

docker run \
--interactive \
--tty \
--volume ".../testapps":/home/user/testapps \
p4a sh -c
'. venv/bin/activate \
&& cd testapps \
&& python setup_testapp_python3.py apk \
--sdk-dir $ANDROID_SDK_HOME \
--ndk-dir $ANDROID_NDK_HOME'

.. note::
On Windows you might need to use quotes and forward-slash path for volume
"/c/Users/.../python-for-android/testapps":/home/user/testapps

.. warning::
On Windows ``gradlew`` will attempt to use 'bash\r' command which is
a result of Windows line endings. For that you'll need to install
``dos2unix`` package into the image.

4. Preserve the distribution you've already built (optional, but recommended):

docker commit $(docker ps --last=1 --quiet) my_p4a_dist

5. Find the ``.APK`` file on this location::

ls -lah testapps
1 change: 1 addition & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Contents
apis
troubleshooting
launcher
docker
contribute
old_toolchain/index.rst

Expand Down
8 changes: 8 additions & 0 deletions pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,14 @@ def apk(self, args):
env["ANDROID_HOME"] = self.ctx.sdk_dir

gradlew = sh.Command('./gradlew')
if exists('/usr/bin/dos2unix'):
# .../dists/bdisttest_python3/gradlew
# .../build/bootstrap_builds/sdl2-python3crystax/gradlew
# if docker on windows, gradle contains CRLF
output = shprint(
sh.Command('dos2unix'), gradlew._path,
_tail=20, _critical=True, _env=env
)
if args.build_mode == "debug":
gradle_task = "assembleDebug"
elif args.build_mode == "release":
Expand Down