Many cell phones and similar devices run a constrained version of the Java Virtual Machine (JVM) called the Sun Java Wireless Toolkit CLDC , Java 2 Micro Edition, or something similar (Sun/Oracle seem to like changing package names). If you want to write a MIDlet that runs on your phone, take a look at Vikram Goyal's detailed tutorial (note: Windows-based commands, but they translate easily into Linux equivalents).

After installing a J2ME SDK (see below) I worked through the examples in Vikram's tutorial and those in a post by Hexist, to compile a simple app. Here's the source for the app with a cleaned up Makefile:

It's a bit annoying getting a J2ME SDK set up on Linux, because the Java Wireless Toolkit requires the old and buggy Java 1.5. On my Gentoo box, I had to mask version of the JDK greater than 1.5 by creating /etc/portage/package.mask/java_wtk containing the line

    >=virtual/jdk-1.6

The Gentoo Portage tree no longer carries Java 1.5 ebuilds, so I installed the Java overlay

# layman -a java-overlay

I then started trying to emerge the JDK with calls to

# emerge -av virtual/jdk

In order for that to succeed I had to:

  • Create /etc/portage/package.keywords/java_wtk containing dev-java/sun-jdk ~x86 to unmask the JDK.
  • Create /etc/portage/package.use/java_wtk containing dev-java/sun-jdk -doc to avoid a fetch restriction on the documentation.
  • Add ACCEPT_LICENSE="dlj-1.1" to /etc/make.conf to accept Sun's license for Java 1.5.

Take a look at the Gentoo Java Guide page for general information on running Java on Gentoo.

Once I got the JDK installed, I installed the Wireless Toolkit in ~/lib/WTK2.5.2 using

$ equery files sun-jdk | grep /bin/javac

to identify /opt/sun-jdk-1.5.0.22/ as the Java SDK path.

Anyhow, after getting all that setup, I learned that my Verizon-provided Casio C721 is running the ancient BREW OS 3.x (Chris Wright's history of mobile games says that BREW went commercial in 2002, but doesn't list specific version release dates). To top that off, they charge $400 for a developer signature needed to install apps on your own phone.

There is an outside chance that they are getting their act together though, with vague press releases about upgrading to Brew MP and lowering the barrier to entry for app-delivery. I'm skeptical, but I suppose time will tell.