How to Develop and Package a Python Kivy App for Android and iOS Using Buildozer
This guide explains how to set up the Kivy framework, write a simple Python app, install required dependencies on macOS, Linux, and CentOS, and use Buildozer to package the app into an Android APK, including troubleshooting tips for common build errors.
Python is versatile but not ideal for app development; Kivy provides a cross‑platform Python framework for creating GUI apps on Linux, macOS, Windows, Android and iOS.
Environment setup
On macOS or Linux install the Kivy dependencies with Homebrew (or apt) and then install Cython and Kivy:
brew install pkg-config sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer pip install cython==0.25 pip install kivyIf the standard install fails, clone the source and install manually:
git clone https://github.com/kivy/kivy python setup.py installTest the installation by running python and importing Kivy; a successful import prints version information.
CentOS 7 installation
Install the required 32‑bit libraries and development packages:
yum install \ make \ mercurial \ automake \ gcc \ gcc-c++ \ SDL_ttf-devel \ SDL_mixer-devel \ khrplatform-devel \ mesa-libGLES \ mesa-libGLES-devel \ gstreamer-plugins-good \ gstreamer \ gstreamer-python \ mtdev-devel \ python-devel \ python-pip \ java-develThen install Cython and Kivy:
pip install Cython==0.20 pip install kivyBuilding an APK with Buildozer
Install Buildozer:
pip install buildozerInitialize the project and edit buildozer.spec as needed:
buildozer initBuild, debug, and deploy the Android package:
buildozer android debug deploy runThe first run downloads the Android SDK and other tools; the process may require a proxy.
Troubleshooting
Common errors include missing 32‑bit libraries (install them via yum -y install --skip-broken … ) and Cython compilation failures (use pip install cython==0.25 ). A bug copying the APK can be fixed by editing /usr/local/lib/python2.7/dist-packages/buildozer/targets/android.py and adjusting the build‑tool version logic.
Buildozer virtual machine
Kivy provides a pre‑configured Buildozer VM image that contains all dependencies, useful when local environments fail.
Overall, the article demonstrates a minimal “Hello, World” Kivy app, shows how to package it for Android, and provides practical tips for resolving typical build issues.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.