Você está na página 1de 3

introduction to programming lab 14: running processing on android

Introduction
In todays lab you will learn how to run your sketches on the Android operating system. The instructions provided should work on Windows XP in the DoC lab machines, allowing you to run your sketches in an Android emulator. Due to some quirks with the lab machine setup, it is not possible to send sketches directly to the emulator from Processings IDE, but a workaround is provided in the following instructions.

Step by step instructions


In this section you will nd step by step instructions on how to setup an Android emulator and then to package and install a Processing sketch for onto it.

Create a default emulator


Boot into Windows XP and nd the Android SDK install directory. It will either be in C:\Program Files or C:\Android-SDK Run the program AVD Manager.exe. This is the Android Virtual Device Manager and it allows you to create emulators with different congurations. We will create a device which has version 2.2. of Android and the Google SDKs. Once created, click the start button in the AVD tool to start the emulator. You should see a rather ugly looking phone which eventually boots up Android.

Download the latest beta version of Processing


The current release version of Android, which is installed on the lab machines, does not work with Android. You need Processing 2.0. 1. Download the beta version of processing 2 (not 1.5!): http://processing.org/download/ Without Java is ne. 2. Uzip it somewhere. A memory stick would be ideal. 3. Run Processing from the folder you just unzipped. (not the version on your Desktop!). 4. On the menu at the top right of the Processing window, select Android instead of Standard.

introduction to programming lab 14: running processing on android

Write a simple test sketch and convert to an Android app


Put the following code into the Processing IDE:
void setup(){ } void draw(){ rect(mouseX, mouseY, 10, 10); }

Now select run in emulator from the Sketch menu. This will then trigger processing to generate a special APK le, which is the packaging format used for android apps. It will take some time and will probably result in an error such as emulator: WARNING: Unable to create sensors port: Unknown error. Thats ok... we are now going to manually install the package and run it on the emulator.

Install the app to the emulator and run


To manually install the package to the emulator, you must rst nd the package that Processing just created for you. This is located in: C:\Documents and Settings\USERNAME\Local Settings\Temp\androidSOMETHING\bin You need to change USERNAME to your username and SOMETHING to a number. Look in the Temp folder and you will see several android... folders. Your apk le will be in the newest one of these folders. Your apk le will end in -debug-unaligned.apk. Now you have the app le, you need to install it onto the emulator. This will be done by downloading the le onto the emulator via a web server. Here are the steps to do that: 1. Place the app le in the public_html folder on your G drive. If you do not have a public_html folder, create one. 2. Rename it to something shorter such as test.apk. 3. You should have an emulator running, if not, click start from the AVD Manager tool. 4. Once the Android system has booted up, unlock the screen by sliding the lock icon to the right. 5. Start the Android web browser by clicking the round icon on the bottom panel of the emulator window. 6. Click on the address bar and type the following address: http://igor.gold.ac.uk/~USERNAME/test.apk changing USERNAME to your username.

introduction to programming lab 14: running processing on android

7. It should download your apk le. You can then install it by clicking the menu button selecting more / downloads then clicking on the apk le in the list. If something goes wrong, double check the address you typed in your main Windows XP web browser. 8. Once installed, open the app and there it is ... running really slowly. See further reading to nd out how to x that, but note youll need to do it on your own machine. 9. To repeat, just re-export from Processing, put the apk onto the G: drive and hit that address again from the emulator.

Further reading
1. The main wiki page for Processing on Android: http://wiki.processing.org/w/Android 2. Want to run the sketches at full speed? Install android-x86 under virtual box for a much faster Android emulator: http://androidspin.com/2011/01/24/howto-install-android-x86-22-in-virtualbox/ Note that you can use the procedure above to install your sketches.

Você também pode gostar