Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Porting J2ME apps to Nokia X using J2ME Android Bridge

From Wiki
Jump to: navigation, search
Featured Article
25 May
2014

This article explains how to port J2ME apps to Nokia X using J2ME Android Bridge.

Article Metadata
Compatibility
Platform(s):
Nokia Asha
Article
Created: ctphong82 (18 Apr 2014)
Last edited: croozeus (26 May 2014)

Contents

Introduction

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.

Preparation

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:

Porting to Nokia X 1.png Porting to Nokia X 2.png Porting to Nokia X 3.png

Step 2: Copy the j2ab_midpapi folder to the default location of your workspace:

Porting to Nokia X 4.png

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:

Porting to Nokia X 5.png Porting to Nokia X 6.png

Step 4: Create a new Java project and name it j2ab_midpapi:

Porting to Nokia X 7.png Porting to Nokia X 8.png

Step 5: Create a new Java project and name it as your J2ME project:

Porting to Nokia X 9.png

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:

Porting to Nokia X 12.png Porting to Nokia X 13.png

Step 7: Repeat step 6 with your J2ME project:

Porting to Nokia X 14.png

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:

Porting to Nokia X 15.png Porting to Nokia X 16.png

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:

Porting to Nokia X 10.png Porting to Nokia X 11.png

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:

Porting to Nokia X 17.png Porting to Nokia X 18.png

Step 11: In the J2ABMIDletActivity project, open theproject.properties file to change the target to android-16:

Porting to Nokia X 19.png

Step 12: In the J2ABMIDletActivity project, open the jad.properties file to declare the midlet class name of your J2ME project:

J2ME NokiaX 1.png

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.
  1. Update any device specific APIs, including input, orientation, and media.
  2. Integrate any Nokia X services required by your app, such as Nokia In-App Billing, HERE maps, Notification APIs.

Tested projects

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.

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.

Known issues:

  • 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)
{
GameUpdate();
GameRender(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.

Summary

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.

This page was last modified on 26 May 2014, at 06:27.
371 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×