First Steps with Processing for Android

I got into mobile development recently. I ported an SDL-based game to the Openmoko FreeRunner and to an iPhone 3GS. Now I’m planning to do some Android development on a Motorola Milestone (the European version of the Droid).

I have previously been using the Processing programming environment on the desktop, so I was delighted to learn that it is now available for Android.

(“Processing is an open source programming language and environment for people who want to create images, animations, and interactions.” It won a Prix Ars Electronica award in the “Net Vision / Net Excellence” category in 2005.)

I am by no means an Android or Processing expert. This article serves mainly as documentation for myself about the steps to build a simple application. If it is also useful for others, so much the better.


(I was using the Android SDK r07 (Android 2.2), Processing for Android revision 0191, and Eclipse 3.6 Helios on Ubuntu 10.10 Maverick for all of the following.)

First Steps with the Android SDK

The Android SDK integrates well into Eclipse, so I decided to use that as my IDE (the SDK can also be used purely on the command line). Although Ubuntu has a version of Eclipse in its repositories, I usually install the latest one from the Eclipse web site. There are several flavors of the IDE, including one for Java development, for C/C++ development, for PHP development, etc. The Android SDK recommends to use the “Eclipse Classic” version. It doesn’t really matter which one you download, though, as you can always install the language-specific plug-ins afterwards. I went with the “Eclipse IDE for C/C++ Linux Developers”.

You will also need a Java Runtime Environment and the Java Development Kit. In Ubuntu, install the packages “openjdk-6-jre” and “openjdk-6-jdk” via the Synaptic Package Manager.

"Alphamask" Processing example running inside the Android emulator

The Android SDK web site has detailed instructions about downloading and installing the SDK. Nothing special there. I followed the instructions and downloaded the Android platforms for versions 1.6, 2.1, and 2.2 (not knowing yet which versions I am planning to target).

To familiarize yourself with the SDK, you should go through the tutorial to create a “Hello, World!” program and run it in the Android emulator.

You might want to run the program directly on your device. There are two ways to do this:

  • When the project is compiled (which happens automatically in the background), an .apk file—an installation package—is created in the “bin” sub-directory. Copy the .apk over to your device using a USB connection and install it from a file explorer app.
  • Set up a debugging connection to your device via USB. This is described below.

To set up a debugging connection, create the file /etc/udev/rules.d/51-android.rules with the following contents:

SUBSYSTEM==”usb”, SYSFS{idVendor}==”22b8“, MODE=”0666”

The number “22b8” is the vendor ID for Motorola. You can either get the ID for your device from this list of vendor IDs or you can plug in your device and run the command “lsusb” to find it:

$ lsusb

Bus 002 Device 007: ID 22b8:41db Motorola PCS Motorola Droid (USB Debug)

(On Windows, it is necessary to install a USB driver for this.)

On the device, you need to enable USB debugging in Menu → “Settings” → “Applications” → “Development” → “USB debugging”.

When you plug in the device, you see a notification about the debugging connection on the device. When you run the program in Eclipse, you can select whether you want to run it in the emulator or on the device.

At this point, you can also use the “adb” tool that comes with the Android SDK to connect to the device and transfer files, install packages, open a shell, etc.

$ ./adb devices
List of devices attached
emulator-5566    device
94367A7041303081    device
$ ./adb -s emulator-5566 shell
# ls

First Steps with Processing

Processing Development Environment (PDE)

Download Processing for Android and extract it to some directory. The command “processing” launches the Processing Development Environment (PDE).

To get started, open the “File” → “Examples” menu and click on one of the sample programs (programs are called “sketches” in Processing) . You can edit the source code in the built-in editor and run the program with “Sketch” → “Run” (Ctrl+R).

To start a sketch in the Android emulator, first enable “Android” → “Android Mode” and then press Ctrl+R.

When you press Ctrl+Shift+R or click “Run” → “Present” while in Android Mode, you can run the skectch directly on an Android device connected via USB (as described earlier).

I prefer to use Eclipse instead of the Processing Development Environment (PDE), especially when the programs get bigger and consist of more than one file. Importing a Processing sketch into Eclipse is straightforward:

  1. Start with an example sketch in the PDE.
  2. Click “File” → “Export” (or press Ctrl+E). This opens the folder that contains the Android project for the sketch.
  3. Make a copy of the sketch folder.
  4. In Eclipse, click “File” → “New” → “Android Project” to start a new project. In the wizard, select “Create project from existing source” and specify the sketch folder as the project location. Click “Finish”.

    New Android Project wizard
  5. Add a reference to “processing-core.jar”: Click “Project” → “Properties”, select “Java Build Path” and go to the “Libraries” tab. Click the “Add JARs…” button and select the file “libs/processing-core.jar” from your project.

    Java Build Path dialog
  6. To run the program, click the “Run As…” button and select “Android Application”. If an Android device is connected via USB, you can choose whether you want to launch the program on the device or inside the emulator.

That’s about as far as I got. Next up, more about the actual coding as I try to get my desktop Processing game to run on Android…

Net Vision / Net Excellence

Portions of this page are reproduced from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.


5 thoughts on “First Steps with Processing for Android”

  1. Great introduction, had my development environment up and running in no time at all. What approach are you using for text input with Processing for Android?

  2. Haven’t done this yet. I’m hoping to combine Processing with regular Android views (menus) at some point.

Leave a Reply

Your email address will not be published. Required fields are marked *