Developing a Python Mobile App with Kivy and Buildozer: Installation, Code, and Packaging Guide
This tutorial walks through using Python's Kivy framework and the Buildozer tool to create, test, and package a cross‑platform mobile app, covering environment setup on macOS, Linux, and CentOS, sample code, build commands, and common troubleshooting tips.
Preparation
To develop a Python app you need the Kivy framework, an open‑source cross‑platform GUI library that supports Linux, macOS, Windows, Android, and iOS. Kivy programs must be packaged for each target platform, for which Buildozer (the official packaging tool) is recommended.
Setting up Kivy Development Environment
Install Kivy for macOS
Install required dependencies:
brew install pkg-config sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamerThen install Cython and Kivy:
pip install cython==0.25 pip install kivyIf the direct install fails, clone and install from source:
git clone https://github.com/kivy/kivy python setup.py installTest the installation by running python and importing Kivy; no errors mean success.
Install Kivy for CentOS 7
Install a long list of 32‑bit libraries and development tools (e.g., yum install make mercurial automake gcc gcc-c++ SDL_ttf-devel ... ) and then install Cython and Kivy:
pip install Cython==0.20 pip install kivyRefer to the official Kivy Linux installation page for more details.
Creating the First Kivy App
Create main.py :
#! -*- coding:utf-8 -*-
from kivy.app import App
class HelloApp(App):
pass
if __name__ == '__main__':
HelloApp().run()Create hello.kv to define the UI:
Label:
text: 'Hello, World! I am nMask'Run the app with python main.py and verify the window appears.
Installing Buildozer
Install Buildozer via pip:
pip install buildozerPackaging the App with Buildozer
In the project directory run:
buildozer initEdit buildozer.spec to set app name, version, etc., then build and deploy:
buildozer android debug deploy runThe first run downloads Android SDK, NDK and other dependencies (requires internet access and may need a proxy).
Common Buildozer Pitfalls
Error: Missing 32‑bit libraries
On CentOS 7 install the required 32‑bit packages, for example:
yum -y install --skip-broken glibc.i686 ... python-matplotliError: Cython compilation failure
Ensure the correct Cython version is installed:
pip install cython==0.25Error: IOError when copying APK
Patch /usr/local/lib/python2.7/dist-packages/buildozer/targets/android.py by importing LooseVersion and adjusting the build‑tools version selection logic as described in the original article.
Buildozer Virtual Machine
Kivy provides a pre‑configured Buildozer VM image (download link provided) for users who cannot resolve dependencies on their own machines.
Kivy Development Example
The article focuses on a minimal “Hello World” example; for more advanced Kivy features see the linked external tutorial.
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.