LINUX J2ME HOWTO

Index and 3D demo Midlet
On Linux/Debian :
 #rzr@nrv:WTK104/$ uname -a
 Linux nrv 2.4.22-amiloa #12 mer nov 5 18:34:14 CET 2003 i686 GNU/Linux

 #root@nrv/# apt-get install j2sdk1.4 # j2sdk1.3 may also works ?

 #rzr@nrv:WTK104/$ java -version
 java version "1.4.1"
 Java(TM) 2 Runtime Environment, Standard Edition (build Blackdown-1.4.1-01)
 Java HotSpot(TM) Client VM (build Blackdown-1.4.1-01, mixed mode)
Download Sun SDK (until a libre one shows up) :
 http://java.sun.com/j2me/
 http://developer.java.sun.com/developer/releases/j2mewtoolkit/
 umask 000 #if root (shared)
 sh j2me_wireless_toolkit-1_0_4_01-bin-linuxi386.bin
 sh j2me_wireless_toolkit-2_0-bin-linuxi386.bin
Test demos :
#rzr@nrv:WTK104/$ ./bin/emulator -Xdescriptor:./apps/games/bin/games.jad
#rzr@nrv:WTK2.1/$ ./bin/emulator -Xdescriptor:./apps/audiodemo/bin/audiodemo.jad
#rzr@nrv:WTK104/$ ./bin/ktoolbar
/opt/WTK2.1/bin/emulator  -XJam:force
Compiling a Simple exemple :
 # http://wireless.java.sun.com/midp/articles/wtoolkit/
 # http://wireless.java.sun.com/midp/articles/wtoolkit/src/HelloMIDlet.java
 # http://www.javasig.com/grokshop.html
 API=/opt/WTK104/lib/midpapi.zip
 #/opt/WTK2.1/lib/midpapi20.zip
 CFLAGS=-bootclasspath ${API}
 PATH+=:/opt/WTK104/bin/

 javac ${CFLAGS} HelloMIDlet.java
 preverify -classpath ${API}  HelloMIDlet
 cd output && \
 jar cf HelloWorld.jar HelloMIDlet.class

 #rzr@nrv:j2me/$ cat output/HelloWorld.jad
 MIDlet-1: HelloWorld, HelloWorld.png, HelloMIDlet
 MIDlet-Jar-Size: 1178
 MIDlet-Jar-URL: HelloWorld.jar
 MIDlet-Name: HelloWorld
 MIDlet-Vendor: Sun Microsystems
 MIDlet-Version: 1.0

 #rzr@nrv:j2me/$ emulator -Xdescriptor:./output/HelloWorld.jad
Note : Preverification performs certain checks on the Java bytecodes ahead of runtime. If this first verification pass is ok, the preverifier annotates the classfiles (using standard Java bytecode "attributes", so that these are still plain old Java bytecodes and will be executable in VMs not aware of the benefits of preverification), and then saves the annotated class files or passes them along to the next tool in the compile chain.

A Graphics application :

http://wireless.java.sun.com/midp/articles/game/

javac -d ./ -bootclasspath /opt/WTK2.1//lib/cldcapi10.zip  \ 
  SimpleGameCanvas.java
javac -d ./ -bootclasspath /opt/WTK2.1//lib/cldcapi10.zip  \
  SimpleGameMIDlet.java
preverify \
 -classpath /opt/WTK2.1/lib/midpapi20.zip:/opt/WTK2.1//lib/cldcapi10.zip:. \
 -d ./ SimpleGameMIDlet
preverify \
 -classpath /opt/WTK2.1/lib/midpapi20.zip:/opt/WTK2.1//lib/cldcapi10.zip:. \
 -d ./ SimpleGameCanvas
jar cf SimpleGame.jar SimpleGameCanvas.class SimpleGameMIDlet.class
emulator \
 -classpath /opt/WTK2.1/lib/midpapi20.zip:/opt/WTK2.1//lib/cldcapi10.zip:. \
 -Xdescriptor:SimpleGame.jad
Other Emulators
Reference SDK : J2ME Mobile Information Device Profile (MIDP) 2.0 http://wwws.sun.com/software/communitysource/j2me/midp/download20.html
Nokia Emu : Nokia Developer's Suite 2.0 for J2ME(TM) http://www.forum.nokia.com/main/1,6566,034-2,00.html Then request for a SN, finally start
# /opt/Nokia/Tools/Nokia_Developers_Suite_for_J2ME/bin/RunNDSforJ2ME.sh
# dos2unix \
 /opt/Nokia/Devices/Series_60_MIDP_Concept_SDK_Beta_0_3_1_Nokia_edition/\
bin/emulator
# /opt/Nokia/Devices/Series_60_MIDP_Concept_SDK_Beta_0_3_1_Nokia_edition/\
bin/emulator Mini3d.jad
Note: Downloading from sun.com is worse that a nightmare, if you have some trouble google and P2P may help. I just Hope some day sun will "open" Java (and before M$ supremacy).
ed2k://|file|j2me_wireless_toolkit-1_0_4_01-bin-linuxi386.bin|8497890|130ff250ee530e90fbf13036e3de1093|
ed2k://|file|j2me_wireless_toolkit-2_1-beta-bin-linux-i386.bin|12901111|18112812c506e6400e24448c4e1df3fd|
ed2k://|file|midp-2_0-src-linux-i686.zip|8082579|efc9fe30de9874cc5df99d8c971f2249|
ed2k://|file|nds_jme_linux_v_2_0.tar.gz|14639906|6b2759b11535b680cd704c87d31fde55|
EXEN PLATEFORM
ExEn is another API for Games (and more than that) see http://www.In-Fusio.com
Porting a MIDP midlet to ExEn does not cause so much troubles, (look at exen.Gamelet and exen.Graphics, but avoid System.* )

They provide a free downloadable SDK for windows, with a few tricks you can use it on linux (not fully usable for me , so far). Hope this may helps :

# Some settings tricks, after installing SDK to w32 folders
ln -fs /mnt/c/Program\ Files ${HOME}/mnt/program_files/
export SDK_DIR=${HOME}/mnt/program_files/InFusioSDK/

# I use Linux j2sdk (might not be the same version)
javac -bootclasspath ${SDK_DIR}etc/lib/ExEnV2.jar \
 -classpath ${SDK_DIR}etc/lib/ExEnV2.jar:. MyClass.java

wine -- ${SDK_DIR}bin/vmtools/VMTrans.exe  -gp -v -w -vd MyClass

# Genrerating ROM # I got an error on that one ? please help
wine -- ${SDK_DIR}bin/vmtools/exenrom/exenrom.exe  \
-gv -dc . -dr ${SDK_DIR}etc/exenrom/ExEnV2/lexen.rom \
-do le_default.exn

Bad reference format
Severe Error!!!
Severe error(FFFF)

# starting simulator worked  (with win32 compiled binaries)
wine -- ${SDK_DIR}bin/simulator_v2/generic/Color/gensimu.exe  le_default.exn
Please help to make exen 100% supported on linux
SIEMENS API
http://www.siemens-mobile.com/developer
Siemens API does not provide a better rasterizer than midp1.0
ed2k://|file|smtkS55_09.exe|8886272|36f7b8d5ad2dc1745c97fffef98680ca|
ed2k://|file|smtk_0_13_2_59.exe|8186089|7b21c7c2bd2fb3da48f8239979fba11f|
SONY ERIKSON API
same old joke : semc_j2me_sdk_v12_09.exe
ed2k://|file|tool_semc_j2me_sdk_v12_09.zip|19607827|63268f7801b6d97f2cea1e85089ff1db|
DOJA / IMODE
http://www.nttdocomo.com/
http://communaute.imode.fr/p21.php
http://communaute.imode.fr/pages/13/idk_doja1.5_vers_1.0.6.zip
ed2k://|file|idk_doja1.5_vers_1.0.6.zip|6042263|fe5951e575793e3c75b02cd81a424c4c|

TROUBLE SHOOTING

Here are some common mistakes and their Solutions
Mime Types
# ** Error installing suite (38): JAR did not have the correct media type, it had application/x-java-archive
# Content-Type: application/x-java-archive

# lynx -mime_header -dump http://rzr.online.fr/docs/java/jclasses/Mini3d.jar
# application/java-archive  jar # @ /etc/apache/mine.types
# or # AddType application/java-archive .jar @ ~/public_html/.htaccess
# AddType text/vnd.sun.j2me.app-descriptor  jad # is that correct also ?
wbmp                                           image/vnd.wap.wbmp
wml                                            text/vnd.wap.wml
wmlc                                           application/vnd.wap.wmlc
wmlsc                                          application/vnd.wap.wmlscriptc
wmlscript                                      text/vnd.wap.wmlscript
ws                                             text/vnd.wap.wmlscript
wsc                                            application/vnd.wap.wmlscriptc


Just mimetype conventions, If you cant access server settings, other cases a php script may hack it and force mime type
Jad description file
** Error installing suite (25): 
A required suite ID attribute in the JAR manifest 
do not match the one in the JAD
Compare MANIFEST.MF & .jad (byte per byte) and size must match
Diffents API
ALERT: Unable to load class javax/microedition/lcdui/game/GameCanvas
"Application not supported" error
WARNING: Attribute value for MicroEdition-Profile defined in JAR manifest is not supported.

midp1.0 devices dont support midp2.0 API :)
WML installation file
#No MIDlet Suites found. Check the URL to make sure it is correct.
#** Error installing suite (34): 
The JAD to be installed is for an existing suite, 
but not from the same domain as the existing one.
I got this error with WTK1, A html file with a absolute link solved this trouble ! (check for modes)
"error 503 service not available"
On Nokia 7650 reaching a not valid .wml
SDK modes
# The connection dropped, and the installation did not complete. 
Please try installing again
# Unable to create MIDlet Mini3dMIDlet
# Warning: Failed to initialize WMA message routing support

# chmod -R a+rwX /opt/WTK104 
# chmod -R a+rwX /opt/WTK104/appdb/
SDK should not be readonly
JVM
ATTENTION: Could not lock System prefs.Unix error code -1113590424.
20 nov. 2003 17:32:31 java.util.prefs.FileSystemPreferences syncWorld
#root@ttyp4[rzr]# mkdir -p /etc/.java/.systemPrefs/
#root@ttyp4[rzr]# #touch /etc/.java/.systemPrefs/.system.lock
This is a inherent java / linux warning
Application Crash
Application dont crash in some emulators (wtk1, wtk2, nokia) but on real device,and No Mesg crash
On Epoc emulator : Program Closed jes-0-javac.microedition.lcdui0@561..
On Nokia 3650 : jes-36e-javax.microedition.lcdui0@1...
I got this bug when merging all my classes into a single one
glass figured out that adding a loop that does setcolor(0,0,0); for 40 ot 80 times or something at the beginning of the paint(graphics g) ..hide that mysterious bug.
Fell free to do further investigations ...

MISC & LINKS

J2me
http://java.sun.com/j2me/docs/
http://wireless.java.sun.com/learn/midp/getstart/
http://www.midlet.org/
http://www.zeroindex.co.uk/
http://www.billday.com/j2me/
Applet emulator http://www.barteo.net/microemulator/
http://www.javasig.com/grokshop.html
http://www.billday.com/j2me/
Bluetooth Hacks : http://bluestumbler.org/
Wap / Wireless etc
http://www.wapforum.org
http://www.nokiafree.org/
http://directory.google.com/Top/Computers/Mobile_Computing/Wireless_Data/WAP/Software/
http://directory.google.com/Top/Games/Video_Games/Computer_Platforms/WAP/
Linux devices : http://www.linuxdevices.com/articles/AT8728350077.html
Java
http://java.sun.com/j2se/1.4.2/docs/api/index.html
http://proguard.sourceforge.net/
http://java.sun.com/docs/books/tutorial/reallybigindex.html
Misc
http://www.tetris.com/game_central/game_central.html
Aikaspektri Demo Digia have released fantastic graphic demo on Assembly 2002 demo party. 3D animations, great effects and music turn your Nokia 7650 into a true dream machine. Really worth seeing. http://my-symbian.com/7650/applications/applications.php?faq=4&fldAuto=23
IRC : #java , #j2me , #nokia , #symbian.com http://www.vidarholen.net/contents/virca/
Misc http://leonard.oxg.free.fr/record16/record16.html
http://www.shakeastick.uklinux.net/exen/
Book: J2ME Game Programming : http://www.amazon.com/exec/obidos/tg/detail/-/1592001181/rzr/#
Java demos : http://equinox.planet-d.net/java/worm3d/
3D Hardware for Mobile http://www.ati.com/products/imageon2300/index.html
C/C++ API : http://www.qualcomm.com/brew/

www.Philippe.COVAL.online.FR
Last modified: Mon Mar 1 21:52:10 CET 2004