pydevices-android-template
PyDevices / pydevices-android-template

A reusable Android template for PyDevices apps.

pydevices-android-template packages a PyDevices app for a phone: python-for-android recipes, a Buildozer-driven sample under p4a_app/ you can replace, and a smoke path that keeps the mobile build honest. On Android there is no MicroPython port — the APK runs CPython with the SDL2 bootstrap, pulling wheels from TestPyPI.

This is not the browser gallery — for in-browser demos see the PyScript Gallery. This repo produces a real APK you install on a phone or emulator.

Source on GitHub

Build a sample APK

requires Android SDK/NDK + buildozer
git clone https://github.com/PyDevices/pydevices-android-template.git
cd pydevices-android-template

./build_android.sh              # prompts for launcher title
./build_android.sh -y           # keep current title (CI)
./build_android.sh --title Paint

# APK under p4a_app/bin/
./scripts/emulator.sh

Runtime / SDL (from p4a_app)

same Runtime idiom as desktop PyDevices apps

board_config

pydevices-desktop supplies neutral display and input endpoints; an application opts into a traffic controller when needed.

import board_config
import eventsys

display_drv = board_config.display_drv
runtime = eventsys.Runtime.from_board_config(board_config)

paint handlers

From p4a_app/paint.py — register events, then run forever.

from board_config import display_drv
from app_runtime import runtime

runtime.on(runtime.events.MOUSEBUTTONDOWN, handler)
runtime.on(runtime.events.MOUSEMOTION, on_motion)
runtime.run_forever()

Gallery vs APK

two different delivery paths — do not conflate
Gallery

PyScript Gallery

Runs in Chrome (or as an installed web app). MicroPython or Pyodide in the browser — no APK, no Android SDK. Ideal for quick tryouts of the same examples.

APK

Native Android

This repo. CPython inside a python-for-android APK with SDL2, usdl2, and TestPyPI wheels. Install with adb or the emulator script — not via the browser gallery.

Customize

clone and replace the sample app

p4a_app/

Sample application: board_config.py, paint.py, main.py, and buildozer.spec (package id org.pydevices.p4a_app). Swap in your own application to ship it.

p4a_recipes/

Namespaced recipes for the pydevices-* TestPyPI distributions, plus pydeviceslvgl for the native pydevices-lvgl wheel. Core package versions are pinned; the LVGL recipe selects a compatible native wheel.

Related