User Tools

Site Tools


doc:appunti:prog:kivy_debian_12_android_11

This is an old revision of the document!


Creating a Kivy app for Android 11 on Debian 12 Bookworm

Kivy is a free and open source Python framework for developing mobile apps, with a single codebase, you will be able to deploy apps on Windows, Linux, macOS, iOS and Android. In this page I will focus on builing an Android app using a GNU/Linux workstation running Debian 12.

The Android target will be Android 11 Red Velvet Cake, this is an aspect that should not be overlooked because starting from Android 10 a series of new features have been introduced by Google that have made the life of Android developers much more complicated. With Android 11 the situation has become further exacerbated.

Many pages on the internet that explain how to compile an Android package on Linux are quite dated; they often refer to the old open source Java SDK - OpenJDK version 8 or 9 - while the current Debian stable distribution ships with OpenJDK 17. Here I tried to revamp all the processes using a freshly installed Debian 12 Bookworm workstation.

Preparing Debian 12

Actually I used a KVM virtual machine to install Debian 12. I allocated a virtual host with 4 Gb of RAM, 2 CPU, 16 Gb of disk space and 1 Gb of swap. While the CPU and RAM specs are acceptable (I can compile my test app in less than one minute), consider to allocate more hard disk space. The bare operating system required about 4 Gb of space, but the building environment required about 8 Gb of space for a simple 30 kb Kivy script!

Minimal Requirements
CPU Intel i3 2.9 GHz, 2 Cores
RAM 4 Gb
Hard Disk 20 Gb

During the install I opted for a tex-only workstation (no desktop environment), but with the SSH server so I can login remotely. Once the installation was terminated, I added the following packages:

apt install git zip unzip openjdk-17-jdk python3-pip autoconf libtool pkg-config \
        zlib1g-dev libncurses5-dev libncursesw5-dev libtinfo5 cmake libffi-dev \
        libssl-dev python3-full lld

We opted to leave the overall system as clean as possibile, so all the developing environmente will be installed in user space, as explained in the following paragraphs.

Problem with pip3 install

Starting with version 12 Bookworm, Debian adheres to the Python Enhancement Proposal 668 titled Marking Python base environments as “externally managed”, so if an unprivileged user tries to install a Python package in its user space $HOME directory, he gets the following error:

error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
    
    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.
    
    See /usr/share/doc/python3.11/README.venv for more information.

note: If you believe this is a mistake, please contact your Python
installation or OS distribution provider. You can override this, at
the risk of breaking your Python installation or OS, by passing
--break-system-packages.
hint: See PEP 668 for the detailed specification.

This means that the Python user space should be remain under the Debian package management system; ading Python packages using pip3 (e.g. downloaded and installed by the user) does not work any more. This is a problem because:

  • Python PEP668 suggests to use the new venv method to install Python libraries in user space, instead of the old plain pip3 method, but this requires you to update all your habits and automation scripts.
  • Some scripts downloaded and executed during the setup process will launch the command pip install --user ..., but the --user option is not compatible with the venv method.
  • The packaging tool python-for-android is required in our building framework, but the installation scripts will probably launch pip install python-for-android, thus failing.

Installation in user space

The entire building framework is composed of several pieces which we will install from direct internet download, unfortunately many of them are not included into the Debian distribution or they are obsolete:

  • Buildozer
  • python-for-android
  • Android NDK
  • Android Commandline Tools for Linux

Web Resources

doc/appunti/prog/kivy_debian_12_android_11.1695388582.txt.gz · Last modified: by niccolo