How to Develop and Package a Python App with Kivy and Buildozer
This tutorial explains how to set up the Kivy framework on macOS and Linux, write a simple Python hello‑world app, test the installation, install and configure Buildozer, and use it to package the app into an Android APK while addressing common build issues.
The article introduces Kivy, an open‑source cross‑platform Python framework for building GUI applications, and explains why Python is not ideal for production mobile apps but can be used for learning or hobby projects.
Preparation
Kivy must be installed as a Python module; it supports Linux, macOS, Windows, Android, and iOS.
Setting up the Kivy development environment
Installation steps for macOS:
brew install pkg-config sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer pip install cython==0.25 pip install kivyIf the above fails, install from source:
git clone https://github.com/kivy/kivy python setup.py installInstallation steps for CentOS 7 include installing many 32‑bit libraries, then:
yum install -y make mercurial automake gcc gcc-c++ ... python-pip java-devel pip install Cython==0.20 pip install kivyAfter installation, test with:
$ python >>> import kivySuccessful import indicates a correct setup.
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 :
Label:
text: 'Hello, World! I am nMask'Run the app with python main.py and verify the window appears.
Installing Buildozer
Buildozer automates packaging Kivy apps for Android and iOS.
pip install buildozerPackaging the app into an APK
In the project directory:
buildozer initEdit buildozer.spec as needed, then run:
buildozer android debug deploy runThe first run downloads Android SDK/NDK and other dependencies. After a successful build, an .apk file appears in the bin folder and can be installed on a device.
Common build issues and fixes
Missing 32‑bit libraries on CentOS can be resolved by installing the extensive list of .i686 packages shown in the article.
Cython version mismatches are fixed by reinstalling a specific version, e.g., pip install cython==0.25 .
File‑not‑found errors during the final copy step can be solved by patching /usr/local/lib/python2.7/dist-packages/buildozer/targets/android.py to use the latest build‑tools version (see the provided code snippet).
Buildozer virtual machine
Kivy provides a pre‑configured Buildozer VM image that contains all dependencies, useful for users who cannot resolve library issues on their own machines.
Download link: kivy-buildozer-vm-2.0.zip
Conclusion
The guide demonstrates a minimal Kivy app workflow, from environment setup to APK generation, and offers troubleshooting tips for common pitfalls.
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.