Android, Processing, Tutorials
comments 12

From Processing to the Android Market [Tutorial]

Android Market - Publish


photo by Lei Gao

Introduction

In this tutorial, you’ll learn how to sign and publish a Processing/Android sketch to the Android Market.
Note that the signing process should be automated and accessible from the PDE quite soon.
You can follow this specific issue here and get an alert when the bug is fixed.

> Pre-requisites (installation steps are covered here):
– Processing 1.5 installed
– Android SDK

> Pre-requisites for Windows users
– Java SE (http://www.oracle.com/technetwork/java/javase/downloads)
– Ant (http://ant.apache.org/manual/install.html)

Step One- Create and export your sketch

If you haven’t already, I encourage you to first read Jer Thorp’s introduction to Mobile development using Processing for how to setup your environment and run your first sketch.

Another page worth visiting is the Processing for Android Wiki

That being said, you can use this sketch as a starting point and modify it to fit your needs.

[sourcecode language="java"]
float radius = 50.0;
float X, Y;
float nX, nY;
int delay = 16;

void setup() {
size(screenWidth, screenHeight);
orientation(PORTRAIT);
background(255);
X = screenWidth / 2;
Y = screenHeight /3;
nX = X;
nY = Y;
}

void draw() {
radius = radius + sin( frameCount / 4 );
X+=(nX-X)/delay;
Y+=(nY-Y)/delay;
stroke(0, 50);
noFill();
ellipse( X, Y, radius, radius );
}

public boolean surfaceTouchEvent(MotionEvent event) {
int numPointers = event.getPointerCount();
if (numPointers == 2) {
background(255);
}
else if (numPointers == 1) {
int pointerId = event.getPointerId(0);
nX = event.getX(0);
nY = event.getY(0);
}
return super.surfaceTouchEvent(event);
}

[/sourcecode]

Start Processing, switch to the Android mode, copy the sketch above and save it.

To export your sketck to an Android Project, from the PDE menu, choose File > Export Android Project
This will create a new Project folder named “android” at the root level of your sketch.

Step Two – Create a key to sign your app

You’ll need a private key to sign your app that you can interactively create using the following command where
“myAndroidKey” is the name you choose for your key and “myAndroidKeyAlias” the alias for this key.

[sourcecode language="bash"]
keytool -genkey -v -keystore myKey.keystore -alias myKeyAlias -keyalg RSA -validity 10000
[/sourcecode]

After answering a couple of questions, you should end up with a .keystore file.
Make sure you remember the key name and alias as well as the password you choose.
The password will be mandatory if you want to later be able to update your app once published.
This key might be used to sign other apps, so you can copy it somewhere and use it when needed without having to generate a new one each time.

Step Three – Configure your project for signing

Important: each time you export your sketch to an Android Project, if the project already exists, il will be renamed into “android-timestampsomething” and a new “android” project will replace it. This means that every modifications that you will do below will be lost, unless you copy the modified files to the new Android project or somehow automate this process.

First copy the .keystore file you generated at step two to the root level of your android folder.

To automate the signing and alignment of the app when building for release (you’ll just be asked for the keystore password), you have to modify the build.properties file and add the following lines (replace the values accordingly):

[sourcecode language="text"]
key.store=myKey.keystore
key.alias=myKeyAlias
[/sourcecode]

Save these changes.

Step Four – Modify the AndroidManifest.xml

Open the AndroidManifest.xml file and set the value of the android:debuggable attribute to false:

[sourcecode language="xml"]
<application android:label="AndroidSketch"
android:icon="@drawable/icon"
android:debuggable="false">
[/sourcecode]

If required, you can change your app’s version by modifying the manifest element attributes.
The values are set by default to the following:
android:versionName=”1.1″ android:versionCode=”1″
If you ever update your app, you’ll have to increment the versionName (1.2 or 2.0) and increment the versionCode (2).
Save these changes.

Step Five- Customize your app icon

Processing provides a default icon in 3 different sizes for your app
You can of course replace them with some others of your choice.
They are located in the following folders:

[sourcecode language="text"]
android/res/drawable/icon.png (48×48 pixels)
android/res/drawable-hdpi/icon.png (72×72 pixels)
android/res/drawable/icon.png (36×36 pixels)
[/sourcecode]

Step Six- Build and sign your app for release

Now, go to the “android” project root and run the following command:

[sourcecode language="bash"]
ant release
[/sourcecode]

Then, enter the password when asked for it.
Make sure you get this message in the end.

[sourcecode language="bash"]BUILD SUCCESSFUL[/sourcecode]

You now have a signed and aligned app in the android/bin folder (ie: myApp-release.apk), ready to be published to the Android Market

Step Seven – Upload your app to the Android Market

The most painful step (for your wallet) of this tutorial: if not already, you’ll have to sign up for an Android Developer account for $25.

Once completed, you can directly publish your app. You’ll need to provide screenshots, a high resolution application icon and some other information to be published along with your application.

You’re done.

I hope to hear from you very soon with some great Android apps that we can review here.


photo by David Cuartielles

  • Pete

    i cant find the build.properties from step 3 in my android folder. where should i find them? 

  • Pete

     there are project.properties, ant.properties and local.properties though. maybe one of them used to be called build.properties? or did i miss a step or installation somewhere?

  • Pelayo Méndez

    That part is outdated. It´s “ant.properties” now instead of “project.properties”

  • Pelayo Méndez

    That part is outdated. It´s “ant.properties” now instead of “project.properties”

  • Pelayo Méndez

    That part is outdated. It´s “ant.properties” now instead of “project.properties”

  • Pelayo Méndez

    That part is outdated. It´s “ant.properties” now instead of “project.properties”

  • Pelayo Méndez

    That part is outdated. It´s “ant.properties” now instead of “project.properties”

  • Pelayo Méndez

    That part is outdated. It´s “ant.properties” now instead of “project.properties”

  • Pelayo Méndez

    That part is outdated. It´s “ant.properties” now instead of “project.properties”

  • Diego

    Thank you very much, 2 years later and this post is still helping people XD

  • Imobach Martín

    Really thank you! If you use processing 1.5.1 with android sdk 7 you shouldn’t have any problem to find build.properties

  • Imobach Martín

    Recently, I’ve successfully uploaded my App using this guide. I’d like to add that if you ever want to change the package name of your app, do the change in the AndroidManifest.xml file that is in your sketch folder, because doing it with the one in the android folder won’t work.
    If you want to enjoy with a processing Tetris® like game for android:
    https://play.google.com/store/apps/details?id=es.kabomi.tetrodomo

    Thanks a lot