Disambiguating Tool Projects for Python on Android

Context: you are a Python developer.  You want to port your app to the Android platform.  You are confused about the many projects that provide tools for this purpose.

Disclaimer: this is a work in progress.  It is a log of what I learned trying to make sense of the subject.

Python on Android

Python is a language.  Android is a platform.  Most development for the Android platform is in the Java language.  It is rare to develop for the Android platform in the Python language.  You probably develop your Python app using tools on a development machine where Python is well supported.  To port your Python app to Android, you need other tools.

Tool Projects for Python on Android

Developers create tools for porting Python to Android and publish projects for the tools:

There is some duplication/sharing between projects.  The projects have similar names but are distinct projects!

The projects differ in:

  • what tools they provide
  • what development environment they support
  • whether they are active and supported

PY4A

This project is about compiling (for Android):

  • the Python interpreter
  • Python modules

The result is not very useful on its own, since the result doesn’t include much IO to a user on the Android platform (because the notion of stdin/stdout/stderr to a console is not in Android?)

The result is very useful as a component in the other tool projects.

Most developers don’t need to understand this project, unless they have custom (non-standard, C language (not pure Python)) Python modules that need to be compiled for Android.

The essential contribution of this project is:

  • the scripts (business process) for compiling Python interpreter and modules using the Android NDK
  • patches to the Python interpreter, needed because of differences in libc on Android?

This project is probably stable and relatively inactive.  Once the project ports a particular version of Python to Android, the project is done until another version of Python is released (or the Android platform changes?)

SL4A

TODO

Android-python27

This project is about packaging (for Android):

  • an app written in Python
  • that uses minimal services of the Android platform ???

????

The project includes an Eclipse project that can be imported into Eclipse IDE.   After telling Eclipse to build, the result is an Android package.

The project also includes source directories from other the other tool projects.  It is not clear how to combine them?  The project does not include an Eclipse project for packaging a Python app that uses Qt?  It requires a certain amount of hacking?

Python for Android

This project is about packaging (for Android):

  • an app written in Python
  • that uses the Kivy cross-platform GUI toolkit
  • that uses services of the Android platform (that are not available through the GUI toolkit)

The development environment for this project is a Linux machine, using a command line.

Contributions:

  • scripts (business processes) for compiling components (distribute.sh)
  • scripts for packaging (build.py)
  • a binding from Python to/from Java (pyjnius)
  • Kivy cross-platform GUI toolkit

This project seems to suffer from a language/culture barrier.  The project documentation in English seems like poor technical writing.

TODO who should use this project

PyDroid

This project is about packaging (for Android):

  • an app written in Python
  • that uses the Qt cross-platform GUI toolkit and the PySide binding to Qt

The development environment for this project is a Linux machine, using a command line.

The project IS a python package.  You install it like you would any other Python package.

To use the project, you execute ‘helper’ or tool programs (scripts written in Python).  For example:

>pydroid check

The project depends on TODO.  During the installation of this project, it checks the dependencies?

Comparing the projects

These projects have the same end result, an Android package (.apk) that includes a Python interpreter:

  • android-python27
  • python-android
  • PyDroid

The projects use different environments (integrated development environments or IDE) on different development platforms:

  • android-python27: Eclipse IDE on Linux, OSX, or Win
  • python-android: command line on Linux
  • PyDroid: command line on Linux with support for QtCreator IDE

The projects have  end results using different GUI toolkits on the target Android:

  • android-python27: minimal native Android GUI (toast?)
  • python-android: Kivy GUI
  • PyDroid: Qt GUI using the PySide binding

Note that the result GUI’s may look more or less native Android (conformant to platform human interface guidelines HIG, or having the native look-and-feel) .  The projects use different toolkits to achieve that.

TODO PyQt binding

The Java bootstrap to exec the Python interpreter

Each project that produces a package includes a Java bootstrap.  The Java bootstrap is a small program in the Java language.  The Java bootstrap is the first thing to be executed on Android (inside the Dalvik VM, which is the Android OS and executes Java programs.)  The Java bootstrap proceeds to exec (fork?) the Python interpreter, which interprets your app written in Python, which may call other Python modules (possibly written in other languages.)  Some of the Python modules may be bridges, ‘system calls’ to the Android OS.

TODO the Ministro bootstrap

IDE Perspectives

Since each project includes a Java bootstrap AND app code in the Python language AND  the Python interpreter in the C language, the projects are multi-language projects.  An IDE (specifically Eclipse) may have different ‘perspectives’ for a project.  One perspective is usually the best choice: the android-python27 project uses a Java perspective.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s