How to Build a Python Mobile App with Kivy and Buildozer: Step‑by‑Step Guide
This article walks through creating a Python‑based mobile app using the Kivy framework, covering environment setup on macOS, Linux, and CentOS, code examples, packaging with Buildozer, troubleshooting common errors, and deploying the resulting APK to Android devices.
I wanted to develop a simple app for fun, but lacked Java experience, so I explored using Python. After discovering the Kivy framework and Buildozer packaging tool, I documented the whole process, including pitfalls and solutions.
Preface
Python is versatile, yet using it for app development is more of a learning exercise; the ecosystem is still immature and prone to bugs, so beginners should proceed cautiously.
Preparation
Kivy is an open‑source, cross‑platform Python framework that supports Linux, macOS, Windows, Android, and iOS. Buildozer is the official tool for packaging Kivy apps for Android and iOS.
Set up Kivy development environment
Installation steps are demonstrated for macOS and CentOS.
install kivy for mac
brew install pkg-config sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer pip install cython==0.25 pip install kivyIf installation fails, clone and install manually:
git clone https://github.com/kivy/kivy python setup.py installinstall kivy for centos7
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-devel pip install Cython==0.20 pip install kivyFor more installation options see the Kivy documentation.
Develop the first Python app with Kivy
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' main.pyserves as the entry point, while hello.kv defines the UI.
Run the app
python main.pySuccessful import of kivy confirms the installation.
Install Buildozer
Buildozer packages Kivy apps for Android and iOS.
pip install buildozerPackage the Kivy app into an APK
Initialize the Buildozer configuration: buildozer init Edit buildozer.spec as needed, then build and deploy: buildozer android debug deploy run The command downloads the Android SDK and other dependencies on first run.
After a successful build, an .apk file appears in the bin directory.
Transfer the APK to an Android device, install, and run:
Buildozer usage
Usage:
buildozer [--profile <name>] [--verbose] [target] <command>...
buildozer --version
Available targets:
android Android target, based on python-for-android project
ios iOS target, based on kivy-ios project
android_old Android target, based on python-for-android project (old toolchain)
Global commands (without target):
distclean Clean the whole Buildozer environment.
help Show the Buildozer help.
init Create an initial buildozer.spec in the current directory
serve Serve the bin directory via SimpleHTTPServer
setdefault Set the default command to run when no arguments are given
version Show the Buildozer version
Target commands:
clean Clean the target environment
update Update the target dependencies
debug Build the application in debug mode
release Build the application in release mode
deploy Deploy the application on the device
run Run the application on the device
serve Serve the bin directory via SimpleHTTPServerCommon Buildozer pitfalls
Missing 32‑bit libraries
On CentOS 7 you may see "You might have missed to install 32bits libs". Install the required 32‑bit packages:
yum -y install --skip-broken glibc.i686 arts.i686 audiofile.i686 bzip2-libs.i686 cairo.i686 cyrus-sasl-lib.i686 dbus-libs.i686 directfb.i686 esound-libs.i686 fltk.i686 freeglut.i686 gtk2.i686 hal-libs.i686 imlib.i686 lcms-libs.i686 lesstif.i686 libacl.i686 libao.i686 libattr.i686 libcap.i686 libdrm.i686 libexif.i686 libgnomecanvas.i686 libICE.i686 libieee1284.i686 libsigc++20.i686 libSM.i686 libtool-ltdl.i686 libusb.i686 libwmf.i686 libwmf-lite.i686 libX11.i686 libXau.i686 libXaw.i686 libXcomposite.i686 libXdamage.i686 libXdmcp.i686 libXext.i686 libXfixes.i686 libxkbfile.i686 libxml2.i686 libXmu.i686 libXp.i686 libXpm.i686 libXScrnSaver.i686 libxslt.i686 libXt.i686 libXtst.i686 libXv.i686 libXxf86vm.i686 lzo.i686 mesa-libGL.i686 mesa-libGLU.i686 nas-libs.i686 nss_ldap.i686 cdk.i686 openldap.i686 pam.i686 popt.i686 pulseaudio-libs.i686 sane-backends-libs-gphoto2.i686 sane-backends-libs.i686 SDL.i686 svgalib.i686 unixODBC.i686 zlib.i686 compat-expat1.i686 compat-libstdc++-33.i686 openal-soft.i686 alsa-oss-libs.i686 redhat-lsb.i686 alsa-plugins-pulseaudio.i686 alsa-plugins-oss.i686 alsa-lib.i686 nspluginwrapper.i686 libXv.i686 libXScrnSaver.i686 qt.i686 qt-x11.i686 pulseaudio-libs.i686 pulseaudio-libs-glib2.i686 alsa-plugins-pulseaudio.i686 python-matplotliCython compilation error
Fix by installing a compatible Cython version:
pip install cython==0.25IOError: No such file or directory
This Buildozer bug occurs when copying the APK. Patch
/usr/local/lib/python2.7/dist-packages/buildozer/targets/android.py:
1. Add import at the top: from distutils.version import LooseVersion 2. Replace the code around line 786 with:
__sdk_dir = self.android_sdk_dir
build_tools_versions = os.listdir(join(__sdk_dir, 'build-tools'))
build_tools_versions = sorted(build_tools_versions, key=LooseVersion)
build_tools_version = build_tools_versions[-1]
gradle_files = ["build.gradle", "gradle", "gradlew"]
is_gradle_build = any((exists(join(dist_dir, x)) for x in gradle_files)) and build_tools_version >= '25.0'Buildozer virtual machine
Kivy provides a pre‑configured Buildozer VM image with all dependencies installed, useful for those who cannot resolve library issues on their own machines.
Download link: http://txzone.net/files/torrents/kivy-buildozer-vm-2.0.zip
Kivy development example
The article focuses on a minimal Kivy + Buildozer workflow to create a simple Python app, leaving more advanced Kivy features for future posts.
Source: CSDN, author nmask
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
