Converting From J2ME

Version 17, last updated by complier at Jan 03 01:57 2009 UTC

All these steps are to be done under Eclipse on Windows, I don't know whether they work using a command line build, or Eclipse under any other platform. It builds against the current version of Andriod, which is 1.0 r2 at the time of writing.

Create a new workspace

In Eclipse select Switch Workspace -> Other... and create a new workspace somewhere.

Technically you don't need to do this, but the instructions assume you have so give it a go.

Create a new Android project in Eclipse

You should have the android plug in for Eclipse installed. If you do, then there will be an option to create an Android project under the new project menu. Select that option.

You want to choose the option to "Create project from existing source" then navigate to the j2ab_adapter folder.

You should have a skeleton project created for you, but it will have compile errors.

Create a new non-Android project in Eclipse

Create a normal Java project in Eclipse now. Again you want to chosoe "Create project from existing source" and navigate to the j2ab_midpapi folder.

In the properties of the Android project (j2ab_adapter), make that project depend on this project.

Right click on the project and go to properties, you'll need to remove the standard Java library from the classpath and add in a dependency on the android.jar file from your Android SDK.

The compile errors should disappear.

Import your project

Assuming you've been developing your MIDP application in Eclipse, find the project(s) for the application and "Import" them into this workspace.

In the properties of the Android project (j2ab_adapter), make that project depend on the project(s) you just imported.

Also, for the project(s) you just imported, make those projects depend on the j2ab_midpapi project and remove any dependencies on the jar files that come with the WTK (very important, you will get verification errors if you don't do this).

See Errors? Fix 'em.

The bridge is incomplete, so you may find you use classes or methods that aren't implemented yet. Eclipse will make this pretty obvious as you'll have compile errors with your classes. You have two options

1) remove the dependency on the unimplemented parts of the API, or

2) implement the bits of the API you need (see below)

Your choice.

Tell the Bridge About your App

This file location will probably change in future, but look for the file

j2ab_bridge/src/jad.properties

This is the equivalent of the jad file for a normal midlet.  Any information you want to have available through the MIDlet.getAppProperty method should be put in here, however you MUST specify one value, the class name of your MIDlet. For example

midlet=name.of.my.midlet.package.NameOfMyMIDlet
param1=The first application parameter
param2=The second application parameter 
xyz123=The third application parameter

GO! 

OK, so you're done. Run up the class J2ABMIDletActivity in the Android debugger (under Eclipse) and see what happens. Hopefully you'll see your application in all its glory.

Any System.out.println statements should be appended to the Android logger, so keep an eye on it.

Implement the Missing Bits of the Adapter

Take a look at the existing code to get an idea of how to implement the missing parts. Of particular note are the lcdui widgets, which use the Android layout xml to configure them. You don't have to do this, but it adds a certain amount of configurability to the style that you wouldn't otherwise enjoy.

Apart from that, lay off the static factory pattern as much as you can while still being faithful to the J2ME spec.

Make a Splash Screen

For technical reasons, we've introduced a splash screen into the loading phase of the bridge. This is used to ascertain the size of the client portion of the screen. You can, however, change the splash screen to look like anything you want in res/layout/splash.xml file, provided it has the attributes

android:layout_width="fill_parent"
android:layout_height="fill_parent"

If that isn't appealing, work out how to return the portion of the screen usable to Display implementations at the time of creation of the Display and fix up the code.