Porting J2ME apps to Nokia X using J2ME Android Bridge
This article explains how to port J2ME apps to Nokia X using J2ME Android Bridge.
J2ME Android Bridge (J2AB) is a set of bridging libraries for porting J2ME applications to run on Android with no changes to the J2ME code.
Unlike MicroEmulator, J2AB isn't an emulator. Instead, it is a set of adapters from the J2ME APIs to the Android APIs. Therefore, you'll need the original J2ME source for the application you are trying to port. The license is public domain so you’re allowed to add your own adapters; for example; to integrate Nokia X services. Remember that you’re always encouraged to submit your work to the repository so that others can re-use it.
1. Set up the development tools for Nokia X by installing:
2. Set up your environment by following the instructions in this guide
3. Download J2ME Android Bridge 0.2.1 and extract it to any folder.
4. Check out the latest J2AB source code from SVN and merge/update it to your J2AB project. This is important, since new classes have been added to the javax.microedition.lcdui.game package from /trunk/j2ab_midpapi/src/main/java/javax/microedition/lcdui/game. This will also update to the latest bug fixes from contributors.
5. Refer to the instructions from the original site to learn how to submit your changes to the J2AB repository.
Porting to Nokia X
Step 1: Open Eclipse and import the j2ab_adapter project into your workspace:
Step 2: Copy the j2ab_midpapi folder to the default location of your workspace:
Step 3: Copy your J2ME project to the default location of your workspace. Note that all source files must be put in the src folder, and all resource files must be put in the res folder:
Step 4: Create a new Java project and name it j2ab_midpapi:
Step 5: Create a new Java project and name it as your J2ME project:
Step 6: Open j2ab_midpapi properties and select Java Build Path. In the Libraries tab, remove the reference to the standard Java library (JRE). Then choose Add External JARs…, browse to android-sdk\sdk\platforms\android-16 and add android.jar library:
Step 7: Repeat step 6 with your J2ME project:
Step 8: Open your J2ME project properties and select Java Build Path. In the Projects and Order and Export tabs, add references to the j2ab_midpapi project:
Step 9: Open J2ABMIDletActivity properties and select Java Build Path. In the Projects and Order and Export tabs, add references to the other two projects:
After this step, there should be no compilation errors, unless your project requires any missing API.
Step 10: (optional) If your J2ME app has any resource files, remember to copy them to the assets folder of the J2ABMIDletActivity project. After that, modify your source code using the correct loading path:
Step 11: In the J2ABMIDletActivity project, open theproject.properties file to change the target to android-16:
Step 12: In the J2ABMIDletActivity project, open the jad.properties file to declare the midlet class name of your J2ME project:
Step 13: Right-click on the J2ABMIDletActivity project, select Run As > 1 Android Application and enjoy seeing your app runn on the Nokia X emulator. :)
Additional steps: Your app is now runnable on the Nokia X emulator. At this point you still need to:
- Fix bugs related to the wrapper APIs (be aware of the known issues section below)
- Adapt the UI for Nokia X devices. Your J2ME project mostly supports lower screen sizes (i.e. 240x320) so you’ll need to update your graphics and code to work on 480x800 resolution.
- Update any device specific APIs, including input, orientation, and media.
- Integrate any Nokia X services required by your app, such as Nokia In-App Billing, HERE maps, Notification APIs.
These J2ME projects have been tested with J2AB. It takes less than 30 minutes to build the first runnable version of these apps on the Nokia X device.
- sudokumaster-jme: https://github.com/nokia-developer/sudokumaster-jme
- drumkit-jme: https://github.com/nokia-developer/drumkit-jme
- battle-tank: https://github.com/nokia-developer/battle-tank
- racer: https://github.com/nokia-developer/racer
- gems-asha: http://1drv.ms/1gORk8S
Limitations and known issues
Limitations: some classes are still missing or don’t have enough methods. However, the framework allows you to easily implement anything you need.
- The anchor point for positioning the image in the drawImage method must not be 0. You can work around this by, for example, using Graphics.LEFT | Graphics.TOP instead of 0.
- If you encounter screen flicker issues, replace GameCanvas with Canvas and move all of your updating and rendering methods to the paint method as follows:
public void paint(Graphics g)
- The showNotify method isn’t invoked when you first launch the app, so you should avoid doing any initialization/loading with showNotify.
- Creating an instance of the Canvas or GameCanvas class in the midlet constructor may cause an exception.
Although there is currently no perfect tool to help you port J2ME apps to Nokia X, J2AB is definitely a good choice and can save you lots of time.