Developing a Python Mobile App with Kivy and Buildozer: Installation, First App, and Packaging Tips
This guide walks through preparing the Kivy development environment on macOS and CentOS, creating a simple hello‑world Python app, installing and using Buildozer to package the app for Android (and iOS), and troubleshooting common build issues with code examples and virtual‑machine recommendations.
Preparation
To develop a Python app you need the Kivy framework, an open‑source cross‑platform Python library that supports Linux, macOS, Windows, Android, and iOS. Kivy code must be packaged for each platform, which is done with the Buildozer tool (or alternatives like python‑for‑android).
Setting Up the Kivy Development Environment
Install Kivy for macOS
Install required dependencies:
<code>brew install pkg-config sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer</code>Install Cython and Kivy:
<code>pip install cython==0.25</code>
<code>pip install kivy</code>If installation fails, clone and install manually:
<code>git clone https://github.com/kivy/kivy</code>
<code>python setup.py install</code>Install Kivy for CentOS 7
Install dependencies:
<code>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</code>Install Cython and Kivy:
<code>pip install Cython==0.20</code>
<code>pip install kivy</code>Refer to the official Kivy Linux installation guide for more details.
Creating Your First Kivy Python App
Create main.py :
<code>#! -*- coding:utf-8 -*-
from kivy.app import App
class HelloApp(App):
pass
if __name__ == '__main__':
HelloApp().run()</code>Create hello.kv to define the UI:
<code>Label:
text: 'Hello, World! I am nMask'</code>The main.py file is the entry point, while the .kv file defines the interface using the class name in lowercase without the "App" suffix.
Running the App
<code>python main.py</code>The app launches and displays a simple window (screenshot omitted).
Installing Buildozer
Buildozer packages Kivy apps for Android and iOS:
<code>pip install buildozer</code>Packaging the App with Buildozer
Initialize the Buildozer configuration:
<code>buildozer init</code>Edit buildozer.spec as needed, then build and deploy:
<code>buildozer android debug deploy run</code>The first run downloads the Android SDK, NDK, and other dependencies (requires internet access and may need a proxy). After a successful build, an .apk file appears in the bin directory and can be installed on an Android device.
Common Buildozer Issues
Increase log level to see detailed errors:
<code>log_level = 2</code>Missing 32‑bit libraries – install required 32‑bit packages on CentOS:
<code>yum -y install --skip-broken glibc.i686 ... python-matplotli</code>Cython compilation errors – ensure the correct Cython version:
<code>pip install cython==0.25</code>IOError during APK copy – patch buildozer/targets/android.py by importing LooseVersion and adjusting the build‑tools selection logic (code snippet provided).
Buildozer Virtual Machine
Kivy provides a pre‑configured Buildozer VM image that includes all dependencies, useful for users who encounter environment issues on their own machines. The VM can be downloaded from the provided torrent link.
Kivy Development Example
The article focuses on a minimal hello‑world example; for more complex applications, refer to the linked Kivy tutorial.
Additional resources and recommended reading links are listed at the end of the original article.
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.