Mobile Development 12 min read

Developing a Python Mobile App with Kivy and Buildozer: Installation, Hello‑World Example, and APK Packaging

This article walks through using the Kivy framework and Buildozer tool to create a simple Python mobile app, covering environment setup on macOS and CentOS, writing a hello‑world program, testing it, packaging it into an APK, and troubleshooting common build issues.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Developing a Python Mobile App with Kivy and Buildozer: Installation, Hello‑World Example, and APK Packaging

Introduction

The author wanted to experiment with building an app using Python instead of Java, discovered the Kivy framework for cross‑platform development, and decided to document the process, noting many pitfalls that were eventually solved with online resources.

Pre‑flight Remarks

While Python is versatile, using it for app development is more suitable for learning or personal projects because the ecosystem is still immature and prone to bugs.

Preparation

Kivy is an open‑source, cross‑platform Python framework that supports Linux, macOS, Windows, Android, and iOS. After installing Kivy, the code must be packaged for each target platform, typically using the Buildozer tool (or python‑for‑android).

Setting Up 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>

Install Kivy for CentOS 7

Install dependencies via yum:

<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>

Then install Cython and Kivy:

<code>pip install Cython==0.20</code>
<code>pip install kivy</code>

Creating the First Kivy Python App

Create main.py with the following content:

<code># -*- coding:utf-8 -*-
from kivy.app import App

class HelloApp(App):
    pass

if __name__ == '__main__':
    HelloApp().run()</code>

Create hello.kv defining the UI:

<code>Label:
    text: 'Hello, World! I am nMask'</code>

Running python main.py launches a window displaying the label.

Installing Buildozer

Buildozer automates packaging Kivy apps for Android and iOS:

<code>pip install buildozer</code>

Packaging the Kivy App into an APK

In the project directory:

<code>buildozer init</code>

This creates buildozer.spec . Edit the file to set the app name, package, etc., then run:

<code>buildozer android debug deploy run</code>

The first run downloads the Android SDK, NDK and other dependencies (requires internet access). After a successful build, an APK appears in the bin folder and can be installed on a device.

Common Buildozer Pitfalls and Fixes

Missing 32‑bit libraries on 64‑bit systems – install the required .i686 packages via yum.

"Error compiling Cython file" – ensure the correct Cython version is installed (e.g., pip install cython==0.25 ).

"IOError: No such file or directory" during APK copy – a known Buildozer bug; patch /usr/local/lib/python2.7/dist-packages/buildozer/targets/android.py by importing LooseVersion and sorting build‑tools versions as described.

Buildozer Virtual Machine

Kivy provides a pre‑configured Buildozer VM image (download link: kivy-buildozer-vm-2.0.zip ) for users who struggle with dependency installation on their own machines.

Conclusion

The guide demonstrates a minimal Kivy + Buildozer workflow for creating and packaging a Python mobile app, while acknowledging that Kivy is still evolving and that developers should be prepared for occasional build issues.

cross‑platformPythonAPKmobile appKivyBuildozer
Python Programming Learning Circle
Written by

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.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.