Developing Android Apps completely in Python (EuroPython 2012 Training)

At this year's EuroPython conference in Florence, Italy, I've been giving a half-day training about Python application development on Android. The training was 240 minutes long and took place on Tuesday July 3rd 2012 at 09:00.

Photo credit: Stefan Kögl


The goal of this training is to show you how to start developing full Android applications using only Python. Different technologies will be demonstrated, including PySide-based QML GUIs using the Necessitas Qt port and the Py4A/SL4A-based approach, which can be combined with Android’s WebKit and re-use Python web frameworks.

While Android already has a good SDK out of the box, being able to use Python instead of Java is a big advantage for some developers - it allows for quicker turnaround times, and reuse of Python libraries. Python on Android uses a native CPython build, so its performance and compatibility is very good. Combined with PySide (which uses a native Qt build) and Qt’s support for OpenGL ES acceleration, you can create fluent UIs even with Python.

The resulting PySide-based applications run on Android, but also at least on Mac OS X, Windows, Linux and Maemo and MeeGo - basically all platforms on which Qt is available. The SL4A/Py4A-based applications will run on Android only, but will be able to utilize Android-specific APIs. Both approaches can also be combined.

Code downloads

Prepare yourself

To get started, you have to download some packages to your host computer, so you can develop and deploy your Python packages to your Android device:

Video (second part only)

Unfortunately, due to technical problems, the first part of the video is not available online. The second part can be found here:

Developing Android apps completely in Python part 2 (YouTube)

Questions from the break

How to install the Android emulator

Don't forget to install the "Android Platform Tools" via $SDK/tools/android!

  2. $SDK/tools/android avd # "android virtual devices"
  3. create emulator
  4. start emulator
  5. "adb devices" shows emulator too

Where to get SL4A for your Android device

Then, to install via adb:

adb install Downloads/sl4a_r5.apk
adb install Downloads/PythonForAndroid_r5.apk

How to install PySide on Mac OS X

See the instructions in the Qt Project Wiki: PySide Binaries for Mac OS X

Other useful instructions

Building CTypes for PGS4A

hg clone

Look into README, copy the environment variable setting + fix paths:

cp Python/build/lib.linux-i686-2.7/ /path/to/pgs4a/private/
cp -rpv Python/Lib/ctypes ~/src/pgs4a-0.9.4/private/lib/
cd /path/to/pgs4a/
rm -rf private/lib/ctypes/test

Running Python from ADB shell

cd /data/data/com.googlecode.pythonforandroid/files/python/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/data/com.googlecode.pythonforandroid/files/python/lib

PGS4A notes

Py4A notes
export ANDROID_NDK=~/pkg/android-ndk-r8/
export PATH=$PATH:$ANDROID_NDK:$ANDROID_NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/


Thomas Perl | contact | 2012 |