Developing and Packaging a Python Mobile App with Kivy and Buildozer
This guide walks through installing Kivy on macOS, Linux, and CentOS, creating a simple Hello‑World Python app, testing it locally, and using Buildozer to package the app into an Android APK (or iOS app), including troubleshooting tips and a virtual‑machine option.
Python is a versatile language but not ideal for native app development; the Kivy framework provides a cross‑platform solution for building Python‑based mobile applications on Linux, macOS, Windows, Android, and iOS.
Preparation : Install Kivy (the core module) and Buildozer (the packaging tool). Kivy handles UI and input, while Buildozer automates the creation of Android/iOS binaries.
Installing Kivy on macOS/Linux : Use Homebrew to install required libraries and then install a specific Cython version followed by Kivy.
<code>brew install pkg-config sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer</code> <code>pip install cython==0.25
pip install kivy</code>If the standard install fails, clone the repository and run the setup script:
<code>git clone https://github.com/kivy/kivy
python setup.py install</code>Installing Kivy on CentOS 7 : Install a long list of 32‑bit dependencies via yum , then install Cython and Kivy with pip.
<code>yum install \
make \
mercurial \
automake \
gcc gcc-c++ \
SDL_ttf-devel SDL_mixer-devel ... (other 32‑bit libs)</code> <code>pip install Cython==0.20
pip install kivy</code>Creating the first app : Write main.py with a minimal App subclass and a hello.kv file that defines a Label displaying “Hello, World!”.
<code>#! -*- coding:utf-8 -*-
from kivy.app import App
class HelloApp(App):
pass
if __name__ == '__main__':
HelloApp().run()
</code> <code>Label:
text: 'Hello, World! I am nMask'
</code>Run the app locally with python main.py to verify the UI appears.
Installing Buildozer : Install the tool via pip and initialise a project.
<code>pip install buildozer</code> <code>buildozer init</code>This creates buildozer.spec , where you can adjust the app name, version, and required permissions.
Packaging for Android : Execute the build command.
<code>buildozer android debug deploy run</code>The first run downloads the Android SDK, NDK, and other dependencies, then compiles the APK and installs it on a connected device. The resulting .apk appears in the bin directory.
Troubleshooting : If errors occur, increase log_level in buildozer.spec to see details. Common issues include missing 32‑bit libraries (resolved by installing the appropriate *.i686 packages) and Cython version mismatches (fixed by reinstalling the required Cython version).
Buildozer virtual machine : An official VM image containing Buildozer and its dependencies can be used to avoid local setup problems; however, developing on your own machine is still recommended.
Overall, the article provides a concise, step‑by‑step tutorial for creating, testing, and packaging a simple Python “Hello World” app with Kivy and Buildozer for multiple platforms.
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.