Processing + Eclipse + Android = Proclipsoid?

Right off the bat I have doubts about using Processing for Android development.  Processing only supports up to Android version 2.2 at this point.  Android is up to 4+ now.  This can’t be good.  But I’m not sure what the repercussions are.  Maybe simple apps will be forwards compatible?  Features like NFC, which only the latest Android versions support, are going to be out of the question, right?  I hope to delve into Android more to answer such questions, but for now I have a few simple steps to get a basic Android app, which leverages Processing, up and running in the Eclipse IDE.

First we need to perform steps as documented by Google to get Android up and running on its own.

1.  Install Android SDK.

Run SDK Manager and select the components from the list as follows.  My screenshot says “update” in some places because I last played with Android a year ago.

 
2.  If you haven’t already, install Eclipse for Java.

3.  Install the Eclipse ADT Plugin.

4.  Create an AVD using Android version 2.2.

5.  Create a blank Android Project again using Android version 2.2.  On the 3rd screen for Package Name, be sure to use something like “com.example.helloandroid” and not “HelloAndroidProcessing” or you’ll get strange errors.

 

 

 
6.  In Eclipse, create a new run configuration using the AVD you created earlier.

7.  Now make sure the Android app runs on its own.  Launch using your new run configuration and you should see the Android emulator pop up.  If you’ve gotten this far, you are ready to develop for Android sans Processing.

8.  If you haven’t already, install Processing (just need to download and unzip).  I’m using version 2.04a.  Stable version 1.5.1 won’t work according to the Processing Wiki.

9.  Now import android-core from your Processing installation.  I created a folder in my new Android project directory called “lib” and placed android-core.jar into it.  Then in Eclipse go to Project -> Properties -> Java Build Path -> Add JARS… and find and select android-core.jar.  (No Proclipsing happening here, though that would be my method of choice for developing Processing in Eclipse for non-Android purposes)

10.  Now make the following code replacement in your main activity class.  Notice I commented out most of what was there by default.  I grabbed a simple Processing sketch from Dan Shiffman’s Learning Processing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.example.helloandroid;
//import android.app.Activity;
//import android.os.Bundle;
import processing.core.*;
 
/*
public class HelloAndroidProcessing extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}
*/
 
public class HelloAndroidProcessing extends PApplet {
    public static void main(String args[]) {
        PApplet.main(new String[] { “–present”, “something.whatever});
    }
 
    //@Override
    //public String sketchRenderer() {
    // return P2D;
    //}
 
    PFont f;
    String message =this text is spinning”;
    float theta;
 
    @Override
    public void setup() {
        size(200,200);
        f = createFont(“Arial”, 20, true);
    }
 
    @Override
    public void draw() {
        background(255);
        fill(0);
        textFont(f);
        translate(width/2,height/2);
        rotate(theta);
        textAlign(CENTER) ;
        text(message,0,0);
        theta += 0.05;
    }
}

Running your run configuration should start up the slow slow emulator.  Once I unlock, I see the following:

 
Also you will now have a file called HelloAndroidProcessing.apk in your bin folder.  Simply copy it over to your Android device and install it and you’ll see your app in action.

3 comments

  1. antoniobrandao

    Hello, I reached the 10th step of your tutorial and I get and error in the line

    public class MainActivity extends PApplet {

    which is:

    —————————-
    Multiple markers at this line
    – The type java.awt.event.FocusListener cannot be resolved. It is indirectly referenced from
    required .class files
    – The type java.awt.event.KeyListener cannot be resolved. It is indirectly referenced from
    required .class files
    – The type java.awt.event.MouseListener cannot be resolved. It is indirectly referenced from
    required .class files
    – The type java.applet.Applet cannot be resolved. It is indirectly referenced from required .class files
    – The hierarchy of the type MainActivity is inconsistent
    – The type java.awt.event.MouseMotionListener cannot be resolved. It is indirectly referenced from
    required .class files
    —————————-

    Both “MainActivity” and “PApplet” words get a red underline in the code.

    If I mouseover “MainActivity”, I get this message:

    “The hierarchy of the type MainActivity is inconsistent”

    If I mouseover “PApplet”, I get this message:

    “The type java.awt.event.MouseListener cannot be resolved. It is indirectly referenced from required .class files”

    —————————-

    Do I have to add AWT to the project?

  2. antoniobrandao

    I updated to JRK 7u7 and added it to Eclipse then added it as a library to my project in project – properties – build path. That solved the errors I had, but it still crashes when I run the app in the Emulator…

    Is this line from your code correct ? PApplet.main(new String[] { “–present”, “something.whatever” });

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>