There are a few options on how you can run buildozer for turning your Kivy app into an APK bundle for Android devices. You can run it directly on your Linux/MacOS/Windows system. You can use a Google Colab Notebook to take advantage of a cloud-based build. Finally, you can run the build process in a Docker container.

The following Dockerfile creates a Debian based image with a buildozer install that can be re-used for your APK builds. The initial image build will take a long time and it will have a rather large size of over 5GB.

FROM python:3.11.8-bookworm

RUN useradd -m -U builder; \
    apt update; \
    apt install -y git zip unzip sudo openjdk-17-jdk python3-pip python3-setuptools python3-dev patch autoconf automake build-essential libtool pkg-config gettext zlib1g-dev libncurses5-dev libncursesw5-dev libtinfo5 cmake libffi-dev libltdl-dev libssl-dev; \
    apt remove ccache;

USER builder
WORKDIR /home/builder
RUN mkdir source

COPY --chown=builder:builder ./ ./source/

RUN echo "export PATH=$PATH:~/.local/bin/" >> .profile; \
    echo "export PATH=$PATH:~/.local/bin/" >> .bashrc; \
    export PATH=$PATH:~/.local/bin/; \
    pip3 install --upgrade buildozer; \
    pip3 install --upgrade Cython==0.29.33 wheel pip setuptools virtualenv; \
    git clone https://github.com/kivy/python-for-android.git; \
    cd source; \
    yes | buildozer android debug; \
    sh -c "rm -Rf *";

VOLUME /home/builder/source

The logic of the above Dockerfile includes installation of the libraries and binaries that buildozer will need, creation of a non-root account and home location, inclusion of the buildozer executable in the PATH, doing an initial build of your app in order for buildozer to download and install additional dependencies, then clearing out the project files to reduce the image.

You can then run the container in your project as follows (build_android.sh):

#!/bin/bash
cd $(dirname "$0")
LOC=$(pwd)
ic=$(docker images | grep -c fdv-apk-builder)
if [ ${ic} -eq 0 ]; then
  docker build -t fdv-apk-builder --progress plain  .
fi
docker run -it -u builder -v ${LOC}:/home/builder/source fdv-apk-builder:latest /bin/sh -lc "cd source; buildozer android debug"

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.