OpenSource For You

Android Apps Made Easy with Processing

Any computer enthusiast would love to create an Android app, a seemingly difficult task. But combine Android with Processing and it is easy. Here’s a simple demonstrat­ion on how to use Android in tandem with Processing to create apps.

-

Android applicatio­n developmen­t has become the coolest thing in the cyber world, for geeks and developers, and there is a great demand for them. Tutorials on Android app developmen­t with Eclipse can become frustratin­g at times. But as always, with the open source world, there is always an alternativ­e way that works just out-of-the-box.

Android is a Linux-based operating system for mobile devices such as smartphone­s and tablet computers. It has been developed by the Open Handset Alliance, led by Google, and other companies. The initial developer of the software, Android Inc, was bought over by Google in 2005. The Android distributi­on was launched in 2007, and the Open Handset Alliance was founded. This is a consortium of 86 hardware, software and telecommun­ications companies devoted to advancing open standards for mobile devices. Google releases the Android code as open source, under the Apache License. The Android Open Source Project (AOSP) is tasked with the maintenanc­e and further developmen­t of Android.

About Processing

Processing is an open source programmin­g language and integrated developmen­t environmen­t (IDE) built for the electronic arts and visual design communitie­s with the purpose of teaching the basics of computer programmin­g in a visual context, and to serve as the foundation for electronic sketchbook­s. The project was initiated in 2001 by Casey Reas and Benjamin Fry. It brings complex graphics programmin­g down to earth for the common man. For more, visit http:// www.processing.org

Before starting this tutorial I would like readers to get acquainted with Processing and its code, which is Java, and learn to write basic programs with it.

So combining Processing with Android can make the open source world livelier. Let’s look at how to develop Android apps using Processing and package them as .apk files.

Prerequisi­tes

For this article I have used Processing 2.1 on Ubuntu 13.10. Processing can be downloaded from http://www.

processing.org/download/?processing Extract it to any folder of your choice. Download the Android SDK from: http://developer. android.com/sdk/index.html. Extract it where ever you like. Go into the extracted Android-SDK folder, into the tools subfolder and run android. In Linux, just open the terminal, cd to that folder and type ./android Through the GUI that launches, update and install all available packages. The main package is the Android SDK Platform-tools You can install the version of Android you want. Since I had a phone with Android 2.3, that is what I installed. Windows users need the Google USB drivers too. Once this is done, your system is ready to develop Android apps.

Coding

On the terminal, cd to the folder in which you have extracted Processing and type ./processing. Make sure that the file Processing has the executable permission set. Start Processing. On the top right corner you will find a box called standard. Click on it and select android. Now write down the code. Most of the code in Processing can be used in Android, but there are certain exceptions. Here’s a small code example, in which we are creating an app to use a finger to draw on the smartphone screen. void setup() { size(640,360); background(100); smooth(); stroke(255); } void draw() {

} if(mousePress­ed==true) {

}

ellipse(mouseX,mouseY,5,5); Press the Play button on the top left of the Processing window and wait till the emulator is loaded with the app. You can also connect your Android device to your PC and make the app run on your device. For that, you will have to activate the USB debugging mode in your Android device. Once you have tested your sketch and are satisfied, it is time to distribute it to the world and for that we have to package it. From the file menu in Processing, select Export Android Project. A folder called Android is created in your sketch folder. Open the terminal and cd to that particular folder. Then generate a private-public keypair, as follows: $ keytool -genkey -v -keystore <keyfile.keystore> -alias <alias> -keyalg RSA -keysize 2048 -validity 10000

This command is nothing but generating a key and calling it draw.keystore. And it is valid for 10,000 days.

Answer all the questions which follow and remember those answers.

Next, build the . apk:

$ ant release

This command will generate a file called sketchname­release-unsigned.apk in the bin folder.

Sign the app:

$ jarsigner -verbose -keystore <Keyfile.keystore> bin/draw-

 ??  ??
 ??  ?? Figure 2: Generate the keystore
Figure 2: Generate the keystore
 ??  ?? Figure 1: Android mode
Figure 1: Android mode

Newspapers in English

Newspapers from India