Tuesday, June 30, 2009

Catch System.out from BlackBerry simulator

Just a little trick I just learned. Sometimes I want a quick and easy logging, just to see what's happening in my program. The easiest approach, specially early in the project is simply using System.out. But when you run your program in the emulator you don't see system out anywhere. To see it you need the command line parameter /app-param=JvmDebugFile.

Just run the emulator as follows:

fledge /handheld=9000 "/app-param=JvmDebugFile:bblog.txt"

In the bblog.txt you will get a lot of info, and your System.out output.

Wednesday, June 17, 2009

Java ME automated build

So far I have built my Java ME application using Sun Java ME SDK 3.0 and before the SDK was available with Sun Wireless Toolkit. But now we need to streamline the process and introduce automated build.

The tool we use for this is ant, with an add-on for Java ME called antenna. Antenna is an open source project, which provides support for operations like obfuscating, updating manifest and JAD files and signing.

To use antenna you need to setup the antenna tasks, using taskdef, and define some properties:

<taskdef resource="antenna.properties" classpath="${basedir}\tools\antenna.jar" />
<property name="wtk.home" location="C:\WTK2.5.2"/>
<property name="wtk.cldc.version" value="1.1"/>
<property name="wtk.midp.version" value="2.0"/>
<property name="wtk.proguard.home" value="${basedir}\tools\proguard4.3"/>

As you can see, we have a directory called tools, where we keep the antenna jar and also a proguard installation, which we need for obfuscation.
Antenna also needs to know where your wireless toolkit is installed and which versions of CLDC and MIDP you use. That's it!

Antennas main function is packaging your application into jar and jad files, preverified, obfuscated and with correct manifest and jad files. You can do this step-by-step, with different tasks for each step, but you can also use the wtkpackage task to make them all.This is the approach we have taken.

<target name="package" depends="compile">
<mkdir dir="${dist.dir}"/>
<copy file="${basedir}/myapp.jad" overwrite="true" failonerror="true" tofile="${dist.dir}/myapp.jad"/>

<wtkpackage jarfile="${dist.dir}/myapp.jar"

<fileset dir="${class.dir}"/>
<fileset dir="${res.dir}"/>

<exclude_from_manifest name="myapp-dir"/>
<exclude_from_manifest name="myapp-host"/>

<copy file="${dist.dir}/myapp.jad" overwrite="true" failonerror="true" tofile="${dist.dir}/myappu.jad"/>


  1. compilation is separate, our package task is made after the compilation
  2. we keep a jad template in the project basedir, which we copy to the dist dir
  3. wtkpackage will create the jar file and update the jad file. We also want it to preverify and obfuscate using proguard
  4. in ${class.dir} we have all classes that should be included
  5. all used resources are in ${res.dir}
  6. we have two parameters in our JAD template that should be only in the JAD file and not in the Manifest file. This allows for changing them without resigning.
  7. as a last step we copy the jad file. This is to have an unsigned copy for use in emulators and phones that don't support the Verisign certificate we use (Nokia S40..)
Signing the application
Antenna also supports signing using the very straightforward wtksign task:

<target name="sign" depends="package">


This will add signature information to the JAD file using the certificate in the keystore and the JAD and jar files are redy to use.

Wednesday, June 03, 2009

Going native on BlackBerry

Our application is currently based on Java ME and uses the lcdui to a 100%, even though there are some fixes to make it work better on BlackBerry. Since BlackBerry is getting more and more popular in the market we have decided to make a version that uses the BlackBerry native UI instead of Java ME standard lcdui.

BlackBerry does not allow combining its native UI with lcdui, which means we will have to convert everything, including the midlet. The majority of the code is however in our own classes, since 90% of tha application is Canvas-based. It seems quite possible to make them work in both environments.

Major changes will be:
- our midlet is replaced by a UIApplication
- the Canvas will be replaced by a MainScreen
- instead of the List we use we will have a KeywordFilterField, which will gives the users better functionality.

Our components will be placed in the MainScreen (instead of a Java ME Canvas). To make this work we will use an interface for painting with two different implementations, that encapsulate Java ME Graphics and BlackBerry Graphics. We will also need to handle the different Font classes and lcdui Image versus BlackBerry Bitmap.

Our immediate gains will be:
- scalable fonts, which is a problem for us now, since the Lcdui fonts on BlackBerry Bold are very large
- some UI improvements, like the KeyWordFilterField instead of the List etc
We will also gain access to possiblities like opening an input field on top of ouyr Canvas, with we really need and have a better looking app.